package com.jinzhi.jzweb.controller;


import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import com.jinzhi.common.domain.DictDO;
import com.jinzhi.common.service.DictService;
import com.jinzhi.common.utils.EhCacheUtil;
import com.jinzhi.common.utils.StringUtil;
import com.jinzhi.jzweb.domain.BookStockDO;
import com.jinzhi.jzweb.domain.ExaminationAllocationDO;
import com.jinzhi.jzweb.domain.MessageplatfromDO;
import com.jinzhi.jzweb.pojo.BookOrderVO;
import com.jinzhi.jzweb.service.BookPurchaseService;
import com.jinzhi.jzweb.service.BookStockService;
import com.jinzhi.jzweb.service.MessageplatfromService;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import com.jinzhi.sms.support.SmsManager;
import com.jinzhi.sys.domain.RoleDO;
import com.jinzhi.sys.domain.UserDO;
import com.jinzhi.sys.domain.UserRoleDO;
import com.jinzhi.sys.service.RoleService;
import com.jinzhi.sys.service.UserRoleService;
import com.jinzhi.sys.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.BookOrderDO;
import com.jinzhi.jzweb.service.BookOrderService;
import com.jinzhi.common.utils.Result;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 * <pre>
 * 订单记录表
 * </pre>
 * <small> 2021-04-08 09:00:12 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/bookOrder")
public class BookOrderController extends BaseController {
	@Autowired
	private BookOrderService bookOrderService;
	@Autowired
	private UserService userService;
	@Autowired
	private RoleService roleService;
	@Autowired
	private UserRoleService userRoleService;
	@Autowired
	private MessageplatfromService messageplatfromService;
	@Autowired
	private BookStockService bookStockService;
	@Autowired
	private BookPurchaseService bookPurchaseService;
	@Autowired
	private SmsManager smsSerevice;
	@Autowired
	private DictService dictService;
	@GetMapping()
	@RequiresPermissions("jzweb:bookOrder:bookOrder")
	String BookOrder(){
	    return "jzweb/bookOrder/bookOrder";
	}

	@GetMapping("/bookOrder2020")
	@RequiresPermissions("jzweb:bookOrder:bookOrder2020")
	String bookOrder2020(){
		return "jzweb/bookOrder/bookOrder2020";
	}



	@GetMapping("/bookOrder1")
	@RequiresPermissions("jzweb:bookOrder:bookOrder1")
	String BookOrder1(){
		return "jzweb/bookOrder/bookOrder1";
	}

	/**
	 * 查询所有学校信息
	 * @return
	 */
	@GetMapping("/selectSchool")
	@ResponseBody
	@Log("查询考试批次信息")
	public  Result<?> selectSchool(@RequestParam(required = false,defaultValue = "1")int pageNumber, @RequestParam(required = false,defaultValue = "10")int pageSize, String name){

		Page<Map<Object,Object>> list=bookOrderService.selectSchool(pageNumber,pageSize,name);
		return Result.ok(list);
	}

	//

	/**
	 * 订单权限查询
	 * @param bookOrderDTO
	 * @return
	 */
	@ResponseBody
	@GetMapping("/list1")
	@RequiresPermissions("jzweb:bookOrder:bookOrder1")
	public Result<Page<BookOrderDO>> list1(BookOrderVO bookOrderDTO){
		// 查询列表数据
		int is=0;
		Long roleId=0l;
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//查询所有用户所属权限
		List<String> organizationNewsDOS = userRoleService.selroleNameList(this.getUserId());

		//for(RoleDO li:listRole){
		for(String name:organizationNewsDOS){

			if(name.equals("订单审核专员")){
				is=2;
			}else if(name.equals("订单发布专员")){
				is=1;
			}else if(name.equals("金职仓库审核专员")){
				is=3;
			}else if(name.equals("超级用户角色")){
				is=4;
				break;
			}else if(name.equals("金英仓库审核专员")){
				is=5;
			}else if(name.equals("市场一部管理员")){
				is=6;
			}else if(name.equals("市场二部管理员")){
				is=7;
			}else if(name.equals("市场一部")){
				is=8;
			}else if(name.equals("市场二部")){
				is=9;
			}else if(name.equals("财务审核发票")){
				is=10;
			}else if(name.equals("管理员")){
				is=11;
				break;
			}
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd");
		Page<BookOrderDO> page =null;
		EntityWrapper<BookOrderDO> wrapper = new EntityWrapper<>();
		wrapper.eq("order_type",1 );
		if(StringUtil.notEmpty(bookOrderDTO.getSchool())&&bookOrderDTO.getSchool()!=null&&bookOrderDTO.getSchool()!=""){
			wrapper.like("school",bookOrderDTO.getSchool() );
		}

		if(bookOrderDTO.getState()!=null){
			wrapper.eq("state",bookOrderDTO.getState() );
		}

		if(bookOrderDTO.getProvince()!=null&&bookOrderDTO.getProvince()!=""&&StringUtils.isNotBlank(bookOrderDTO.getProvince())){
			wrapper.like("province", bookOrderDTO.getProvince());
		}

		if(bookOrderDTO.getStateMoney()!=null){
			wrapper.eq("state_money", bookOrderDTO.getStateMoney().toString());
		}

		if(bookOrderDTO.getRefundState()!=null){
			wrapper.eq("refund_state", bookOrderDTO.getRefundState().toString());
		}

		if(StringUtils.isNotBlank(bookOrderDTO.getStartTime())){
			Date format = null;
			try {
				format = sdf.parse(bookOrderDTO.getStartTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			wrapper.ge("order_createtime",format);

		}

		if(StringUtils.isNotBlank(bookOrderDTO.getEndTime())){
			Date format = null;
			try {
				format = sdf.parse(bookOrderDTO.getEndTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			wrapper.le("order_createtime",format);

		}
		wrapper.eq("order_type",1);
		List<RoleDO>  listRole=roleService.findAll();
		Long chOO1=0l;
		Long chOO2=0l;
		wrapper.orderBy("id",false);
		if(is==4){

			page = bookOrderService.selectPage(getPage(BookOrderDO.class), wrapper);
		//3  5  加入判断 只查询出审核通过的
		}else if(is==3){
			//wrapper.andNew().eq("state",1).or().eq("state",3).or().eq("state",4);

			page = bookOrderService.selectPage(getPage(BookOrderDO.class)
					, wrapper);

		}else if(is==2){
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		else if(is==1){
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		else if(is==5){
			//wrapper.andNew().eq("state",1).or().eq("state",3).or().eq("state",4);
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		//市场一部管理员
		else if(is==6){
			List lists=new ArrayList();
			List list=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场一部")||roleDO.getRoleName().equals("市场一部管理员")){
					chOO1=roleDO.getId();
					lists.add(chOO1);
					//break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.in("roleId",lists);

			Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);

			List<UserRoleDO> userRoleDOS=	page1.getRecords();
			for(UserRoleDO users:userRoleDOS){
				list.add(users.getUserId());
			}

			wrapper.in("creare_user",list);
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		//市场二部管理员
		else if(is==7){
			List list=new ArrayList();
			List lists=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场二部")||roleDO.getRoleName().equals("市场二部管理员")){
					chOO2=roleDO.getId();
					lists.add(chOO2);
					//break;
				}
			}

			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			//wrapper1.eq("roleId",chOO2);
			wrapper1.in("roleId",lists);

			Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);

			List<UserRoleDO> userRoleDOS=	page1.getRecords();
			for(UserRoleDO users:userRoleDOS){
				list.add(users.getUserId());
			}

			wrapper.in("creare_user",list);
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		//市场一部
		else if(is==8){
			wrapper.eq("creare_user",this.getUserId() );
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		//市场二部
		else if(is==9){
			wrapper.eq("creare_user",this.getUserId() );
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}else if(is==10){
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}else if(is==11){
			page = bookOrderService.selectPage(getPage(BookOrderDO.class), wrapper);
		}


		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
			BookOrderDO obj = (BookOrderDO) page.getRecords().get(i);
			BookOrderVO bookOrderVO=new BookOrderVO();
			bookOrderVO.setCounty(obj.getCounty());
			bookOrderVO.setAddress(obj.getAddress());
			if(obj.getOrderCreatetime()!=null){
				bookOrderVO.setOrderCreatetimes(sdfs.format(obj.getOrderCreatetime()));
			}
			bookOrderVO.setCity(obj.getCity());
			bookOrderVO.setDiscount(obj.getDiscount());
			bookOrderVO.setGoodsUser(obj.getGoodsUser());
			bookOrderVO.setAdminRemarks(obj.getAdminRemarks());
			bookOrderVO.setWarehouse(obj.getWarehouse());
			bookOrderVO.setState(obj.getState());
			bookOrderVO.setProvince(obj.getProvince());
			bookOrderVO.setOrderUser(obj.getOrderUser());
			bookOrderVO.setRemarks(obj.getRemarks());
			bookOrderVO.setOrderNumber(obj.getOrderNumber());
			bookOrderVO.setOrderMoney(obj.getOrderMoney());
			bookOrderVO.setMobile(obj.getMobile());
			bookOrderVO.setId(obj.getId());
			bookOrderVO.setOrderPrimary(obj.getOrderPrimary());
			bookOrderVO.setOrderSenior(obj.getOrderSenior());
			bookOrderVO.setOrderIntermediate(obj.getOrderIntermediate());
			bookOrderVO.setInvoiceAddress(obj.getInvoiceAddress());
			bookOrderVO.setPost(obj.getPost());
			bookOrderVO.setInvoiceType(obj.getInvoiceType());
			bookOrderVO.setStateCollection(obj.getStateCollection());
			bookOrderVO.setOrderCode(obj.getOrderCode());
			bookOrderVO.setYear(obj.getYear());
			bookOrderVO.setExpressName(obj.getExpressName());
			//计算原价
			BigDecimal bigDecimalYuanJia=new BigDecimal(0);

			//折扣跟订单数量
			//计算基础知识折扣价格
			BigDecimal money=	BigDecimal.valueOf(obj.getOrderNumber());
			//初级价格
			BigDecimal money1=	BigDecimal.valueOf(obj.getOrderPrimary());
			//中级价格
			BigDecimal money2=	BigDecimal.valueOf(obj.getOrderIntermediate());
			//高级价格
			BigDecimal money3=	BigDecimal.valueOf(obj.getOrderSenior());

			BigDecimal orderMoney1=new BigDecimal(0);
			BigDecimal orderMoney2=new BigDecimal(0);
			BigDecimal orderMoney3=new BigDecimal(0);
			BigDecimal orderMoney4=new BigDecimal(0);

			Wrapper<BookStockDO> wrapper1s = new EntityWrapper();
			wrapper1s.eq("book_types", obj.getBookId());
			//查询价格
			List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper1s);


			for(BookStockDO bookm:bookPurchaseDO){
				if(bookm.getBookType().indexOf("基础知识")!=-1){
					orderMoney1=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("初级")!=-1){
					orderMoney2=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("中级")!=-1){
					orderMoney3=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("高级")!=-1){
					orderMoney4=bookm.getMoney();
				}
			}
			//计算基础知识价格
			BigDecimal orderMoney=(money.multiply(orderMoney1));

			//计算初级价格
			BigDecimal orderMoneys1=(money1.multiply(orderMoney2));

			//计算中级价格
			BigDecimal orderMoneys2=(money2.multiply(orderMoney3));

			//计算高级价格
			BigDecimal orderMoneys3=(money3.multiply(orderMoney4));

			bigDecimalYuanJia=orderMoney.add(orderMoneys1).add(orderMoneys2).add(orderMoneys3);
			//原价
			bookOrderVO.setPrimaryMoney(bigDecimalYuanJia);

			UserDO userDO=userService.selectById(obj.getCreareUser());
			if(userDO!=null){
				bookOrderVO.setCreateUserNmae(userDO.getName());
			}

			UserDO userDO1=userService.selectById(obj.getOrderUser());
			if(userDO1!=null){
				bookOrderVO.setOrderUserName(userDO1.getName());
			}
			UserDO userDO2=userService.selectById(obj.getGoodsUser());
			if(userDO2!=null){
				bookOrderVO.setGoodsUserName(userDO2.getName());
			}
			//书籍名称
			//if(bookStockDO!=null){
			bookOrderVO.setBookName(obj.getBookId());
			//}
			bookOrderVO.setSchool(obj.getSchool());
			bookOrderVO.setActualMoney(obj.getActualMoney());
			bookOrderVO.setWarehouse(obj.getWarehouse());
			bookOrderVO.setBillingAccountNumber(obj.getBillingAccountNumber());
			bookOrderVO.setBillingAddress(obj.getBillingAddress());
			bookOrderVO.setBillingMailbox(obj.getBillingMailbox());
			bookOrderVO.setBillingAccountNumber(obj.getBillingAccountNumber());
			bookOrderVO.setBillingNumber(obj.getBillingNumber());
			bookOrderVO.setStateMoney(obj.getStateMoney());
			bookOrderVO.setStateMoneyMark(obj.getStateMoneyMark());
			bookOrderVO.setAddressee(obj.getAddressee());
			bookOrderVO.setBillingName(obj.getBillingName());
			bookOrderVO.setRefundMoney(obj.getRefundMoney());
			bookOrderVO.setRefundState(obj.getRefundState());
			bookOrderVO.setDiscountSenior(obj.getDiscountSenior());
			bookOrderVO.setDiscountIntermediate(obj.getDiscountIntermediate());
			bookOrderVO.setDiscountPrimary(obj.getDiscountPrimary());
			bookOrderVO.setExlUrl(obj.getExlUrl());//primaryDiscountPayment
			//基础知识
			bookOrderVO.setBasicsPayment(obj.getBasicsPayment());
			//初级折扣价
			bookOrderVO.setPrimaryDiscountPayment(obj.getPrimaryDiscountPayment());
			//中级折扣价
			bookOrderVO.setIntermediatePayment(obj.getIntermediatePayment());
			//高级折扣价
			bookOrderVO.setSeniorPayment(obj.getSeniorPayment());
			bookOrderVO.setDepartment(obj.getDepartment());
			list.add(bookOrderVO);
		}
		page.setRecords(list);
		return Result.ok(page);
	}

	/**
	 * 订单权限查询
	 * 2021 年查询
	 * @param bookOrderDTO
	 * @return
	 */
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:bookOrder:bookOrder")
	public Result<Page<BookOrderDO>> list(BookOrderVO bookOrderDTO){
		// 查询列表数据
		int is=0;
		Long roleId=0l;
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//查询所有用户所属权限
		List<String> organizationNewsDOS = userRoleService.selroleNameList(this.getUserId());
		String department=null;
		//for(RoleDO li:listRole){
			for(String name:organizationNewsDOS){

				if(name.equals("订单审核专员")){
					is=2;
				}else if(name.equals("订单发布专员")){
					is=1;
				}else if(name.equals("金职仓库审核专员")){
					is=3;
				}else if(name.equals("超级用户角色")){
					is=4;
					break;
				}else if(name.equals("金英仓库审核专员")){
					is=5;
				}else if(name.equals("市场一部管理员")){
					is=6;
					break;
				}else if(name.equals("市场二部管理员")){
					is=7;
					break;
				}else if(name.equals("市场一部")){
					is=8;
					break;
				}else if(name.equals("市场二部")){
					is=9;
					break;
				}else if(name.equals("财务审核发票")){
					is=10;
				}else if(name.equals("管理员")){
					is=11;
					break;
				}
			}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd");
		Page<BookOrderDO> page =null;
		EntityWrapper<BookOrderDO> wrapper = new EntityWrapper<>();

		if(StringUtil.notEmpty(bookOrderDTO.getSchool())&&bookOrderDTO.getSchool()!=null&&bookOrderDTO.getSchool()!=""){
			wrapper.like("school",bookOrderDTO.getSchool() );
		}
		wrapper.eq("year",2021);
		if(bookOrderDTO.getState()!=null){
			wrapper.eq("state",bookOrderDTO.getState() );
		}

		if(bookOrderDTO.getProvince()!=null&&bookOrderDTO.getProvince()!=""&&StringUtils.isNotBlank(bookOrderDTO.getProvince())){
			wrapper.like("province", bookOrderDTO.getProvince());
		}

		if(bookOrderDTO.getStateMoney()!=null){
			wrapper.eq("state_money", bookOrderDTO.getStateMoney().toString());
		}

		if(bookOrderDTO.getRefundState()!=null){
			wrapper.eq("refund_state", bookOrderDTO.getRefundState().toString());
		}

		if(StringUtils.isNotBlank(bookOrderDTO.getStartTime())){
			Date format = null;
			try {
				format = sdf.parse(bookOrderDTO.getStartTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			wrapper.ge("order_createtime",format);

		}
		wrapper.eq("order_type",0);
		if(StringUtils.isNotBlank(bookOrderDTO.getEndTime())){
			Date format = null;
			try {
				format = sdf.parse(bookOrderDTO.getEndTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			wrapper.le("order_createtime",format);

		}

		List<RoleDO>  listRole=roleService.findAll();
		Long chOO1=0l;
		Long chOO2=0l;
		wrapper.orderBy("id",false);
			if(is==4){

				page = bookOrderService.selectPage(getPage(BookOrderDO.class), wrapper);

			}else if(is==3){
				page = bookOrderService.selectPage(getPage(BookOrderDO.class)
						, wrapper);

			}else if(is==2){
				page = bookOrderService.selectPage(getPage(BookOrderDO.class),
						 wrapper);
			}
			else if(is==1){
				page = bookOrderService.selectPage(getPage(BookOrderDO.class),
						 wrapper);
			}
			else if(is==5){
				page = bookOrderService.selectPage(getPage(BookOrderDO.class),
						 wrapper);
			}
			//市场一部管理员
			else if(is==6){
				List lists=new ArrayList();
				List list=new ArrayList();
				for(RoleDO roleDO:listRole){
					if(roleDO.getRoleName().equals("市场一部")||roleDO.getRoleName().equals("市场一部管理员")){
						chOO1=roleDO.getId();
						lists.add(chOO1);
						//break;
					}
				}
				EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

				wrapper1.in("roleId",lists);

				Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);

			List<UserRoleDO> userRoleDOS=	page1.getRecords();
					for(UserRoleDO users:userRoleDOS){
						list.add(users.getUserId());
					}

				wrapper.in("creare_user",list);
				page = bookOrderService.selectPage(getPage(BookOrderDO.class),
						wrapper);
			}
			//市场二部管理员
			else if(is==7){
				List list=new ArrayList();
				List lists=new ArrayList();
				for(RoleDO roleDO:listRole){
					if(roleDO.getRoleName().equals("市场二部")||roleDO.getRoleName().equals("市场二部管理员")){
						chOO2=roleDO.getId();
						lists.add(chOO2);
						//break;
					}
				}

				EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

				//wrapper1.eq("roleId",chOO2);
				wrapper1.in("roleId",lists);

				Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);

				List<UserRoleDO> userRoleDOS=	page1.getRecords();
				for(UserRoleDO users:userRoleDOS){
					list.add(users.getUserId());
				}

				wrapper.in("creare_user",list);
				page = bookOrderService.selectPage(getPage(BookOrderDO.class),
						wrapper);
			}
			//市场一部
			else if(is==8){
				wrapper.eq("creare_user",this.getUserId() );
				page = bookOrderService.selectPage(getPage(BookOrderDO.class),
						wrapper);
			}
			//市场二部
			else if(is==9){
				wrapper.eq("creare_user",this.getUserId() );
				page = bookOrderService.selectPage(getPage(BookOrderDO.class),
						wrapper);
			}else if(is==10){
				page = bookOrderService.selectPage(getPage(BookOrderDO.class),
						wrapper);
			}else if(is==11){
				page = bookOrderService.selectPage(getPage(BookOrderDO.class), wrapper);
			}


		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				BookOrderDO obj = (BookOrderDO) page.getRecords().get(i);
			BookOrderVO bookOrderVO=new BookOrderVO();
			bookOrderVO.setCounty(obj.getCounty());
			bookOrderVO.setAddress(obj.getAddress());
			if(obj.getOrderCreatetime()!=null){
				bookOrderVO.setOrderCreatetimes(sdfs.format(obj.getOrderCreatetime()));
			}

			bookOrderVO.setCity(obj.getCity());
			bookOrderVO.setDiscount(obj.getDiscount());
			bookOrderVO.setGoodsUser(obj.getGoodsUser());
			bookOrderVO.setAdminRemarks(obj.getAdminRemarks());
			bookOrderVO.setWarehouse(obj.getWarehouse());
			bookOrderVO.setState(obj.getState());
			bookOrderVO.setProvince(obj.getProvince());
			bookOrderVO.setOrderUser(obj.getOrderUser());
			bookOrderVO.setRemarks(obj.getRemarks());
			bookOrderVO.setOrderNumber(obj.getOrderNumber());
			bookOrderVO.setOrderMoney(obj.getOrderMoney());
			bookOrderVO.setMobile(obj.getMobile());
			bookOrderVO.setId(obj.getId());
			bookOrderVO.setOrderPrimary(obj.getOrderPrimary());
			bookOrderVO.setOrderSenior(obj.getOrderSenior());
			bookOrderVO.setOrderIntermediate(obj.getOrderIntermediate());
			bookOrderVO.setInvoiceAddress(obj.getInvoiceAddress());
			bookOrderVO.setPost(obj.getPost());
			bookOrderVO.setInvoiceType(obj.getInvoiceType());
			bookOrderVO.setStateCollection(obj.getStateCollection());
			bookOrderVO.setOrderCode(obj.getOrderCode());

			bookOrderVO.setExpressName(obj.getExpressName());
			bookOrderVO.setYear(obj.getYear());
			//计算原价
			BigDecimal bigDecimalYuanJia=new BigDecimal(0);

			bookOrderVO.setDepartment(department);
			//折扣跟订单数量
			//计算基础知识折扣价格
			BigDecimal money=	BigDecimal.valueOf(obj.getOrderNumber());
			//初级价格
			BigDecimal money1=	BigDecimal.valueOf(obj.getOrderPrimary());
			//中级价格
			BigDecimal money2=	BigDecimal.valueOf(obj.getOrderIntermediate());
			//高级价格
			BigDecimal money3=	BigDecimal.valueOf(obj.getOrderSenior());

			BigDecimal orderMoney1=new BigDecimal(0);
			BigDecimal orderMoney2=new BigDecimal(0);
			BigDecimal orderMoney3=new BigDecimal(0);
			BigDecimal orderMoney4=new BigDecimal(0);

			Wrapper<BookStockDO> wrapper1s = new EntityWrapper();
			wrapper1s.eq("book_types", obj.getBookId());
			//查询价格
			List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper1s);


			for(BookStockDO bookm:bookPurchaseDO){
				if(bookm.getBookType().indexOf("基础知识")!=-1){
					orderMoney1=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("初级")!=-1){
					orderMoney2=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("中级")!=-1){
					orderMoney3=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("高级")!=-1){
					orderMoney4=bookm.getMoney();
				}
			}
			//计算基础知识价格
			BigDecimal orderMoney=(money.multiply(orderMoney1));

			//计算初级价格
			BigDecimal orderMoneys1=(money1.multiply(orderMoney2));

			//计算中级价格
			BigDecimal orderMoneys2=(money2.multiply(orderMoney3));

			//计算高级价格
			BigDecimal orderMoneys3=(money3.multiply(orderMoney4));

			bigDecimalYuanJia=orderMoney.add(orderMoneys1).add(orderMoneys2).add(orderMoneys3);
			//原价
			bookOrderVO.setPrimaryMoney(bigDecimalYuanJia);

			UserDO userDO=userService.selectById(obj.getCreareUser());
			if(userDO!=null){
				bookOrderVO.setCreateUserNmae(userDO.getName());
			}

			UserDO userDO1=userService.selectById(obj.getOrderUser());
			if(userDO1!=null){
				bookOrderVO.setOrderUserName(userDO1.getName());
			}
			UserDO userDO2=userService.selectById(obj.getGoodsUser());
			if(userDO2!=null){
				bookOrderVO.setGoodsUserName(userDO2.getName());
			}
			//书籍名称
			//if(bookStockDO!=null){
				bookOrderVO.setBookName(obj.getBookId());
			//}
			bookOrderVO.setSchool(obj.getSchool());
			bookOrderVO.setActualMoney(obj.getActualMoney());
			bookOrderVO.setWarehouse(obj.getWarehouse());
			bookOrderVO.setBillingAccountNumber(obj.getBillingAccountNumber());
			bookOrderVO.setBillingAddress(obj.getBillingAddress());
			bookOrderVO.setBillingMailbox(obj.getBillingMailbox());
			bookOrderVO.setBillingAccountNumber(obj.getBillingAccountNumber());
			bookOrderVO.setBillingNumber(obj.getBillingNumber());
			bookOrderVO.setStateMoney(obj.getStateMoney());
			bookOrderVO.setStateMoneyMark(obj.getStateMoneyMark());
			bookOrderVO.setAddressee(obj.getAddressee());
			bookOrderVO.setBillingName(obj.getBillingName());
			bookOrderVO.setRefundMoney(obj.getRefundMoney());
			bookOrderVO.setRefundState(obj.getRefundState());
			bookOrderVO.setDiscountSenior(obj.getDiscountSenior());
			bookOrderVO.setDiscountIntermediate(obj.getDiscountIntermediate());
			bookOrderVO.setDiscountPrimary(obj.getDiscountPrimary());
			bookOrderVO.setExlUrl(obj.getExlUrl());//primaryDiscountPayment


			//基础知识
			bookOrderVO.setBasicsPayment(obj.getBasicsPayment());
			//初级折扣价
			bookOrderVO.setPrimaryDiscountPayment(obj.getPrimaryDiscountPayment());
			//中级折扣价
			bookOrderVO.setIntermediatePayment(obj.getIntermediatePayment());
			//高级折扣价
			bookOrderVO.setSeniorPayment(obj.getSeniorPayment());
			bookOrderVO.setDepartment(obj.getDepartment());
			list.add(bookOrderVO);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	/**
	 * 订单权限查询
	 * 2021 年查询
	 * @param bookOrderDTO
	 * @return
	 */
	@ResponseBody
	@GetMapping("/list2020")
	@RequiresPermissions("jzweb:bookOrder:bookOrder2020")
	public Result<Page<BookOrderDO>> list2020(BookOrderVO bookOrderDTO){
		// 查询列表数据
		int is=0;
		Long roleId=0l;
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//查询所有用户所属权限
		List<String> organizationNewsDOS = userRoleService.selroleNameList(this.getUserId());
		String department=null;
		//for(RoleDO li:listRole){
		for(String name:organizationNewsDOS){

			if(name.equals("订单审核专员")){
				is=2;
			}else if(name.equals("订单发布专员")){
				is=1;
			}else if(name.equals("金职仓库审核专员")){
				is=3;
			}else if(name.equals("超级用户角色")){
				is=4;
				break;
			}else if(name.equals("金英仓库审核专员")){
				is=5;
			}else if(name.equals("市场一部管理员")){
				is=6;
				break;
			}else if(name.equals("市场二部管理员")){
				is=7;
				break;
			}else if(name.equals("市场一部")){
				is=8;
				break;
			}else if(name.equals("市场二部")){
				is=9;
				break;
			}else if(name.equals("财务审核发票")){
				is=10;
			}else if(name.equals("管理员")){
				is=11;
				break;
			}
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd");
		Page<BookOrderDO> page =null;
		EntityWrapper<BookOrderDO> wrapper = new EntityWrapper<>();

		if(StringUtil.notEmpty(bookOrderDTO.getSchool())&&bookOrderDTO.getSchool()!=null&&bookOrderDTO.getSchool()!=""){
			wrapper.like("school",bookOrderDTO.getSchool() );
		}
		wrapper.eq("year",2020);
		if(bookOrderDTO.getState()!=null){
			wrapper.eq("state",bookOrderDTO.getState() );
		}

		if(bookOrderDTO.getProvince()!=null&&bookOrderDTO.getProvince()!=""&&StringUtils.isNotBlank(bookOrderDTO.getProvince())){
			wrapper.like("province", bookOrderDTO.getProvince());
		}

		if(bookOrderDTO.getStateMoney()!=null){
			wrapper.eq("state_money", bookOrderDTO.getStateMoney().toString());
		}

		if(bookOrderDTO.getRefundState()!=null){
			wrapper.eq("refund_state", bookOrderDTO.getRefundState().toString());
		}

		if(StringUtils.isNotBlank(bookOrderDTO.getStartTime())){
			Date format = null;
			try {
				format = sdf.parse(bookOrderDTO.getStartTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			wrapper.ge("order_createtime",format);

		}
		wrapper.eq("order_type",0);
		if(StringUtils.isNotBlank(bookOrderDTO.getEndTime())){
			Date format = null;
			try {
				format = sdf.parse(bookOrderDTO.getEndTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			wrapper.le("order_createtime",format);

		}

		List<RoleDO>  listRole=roleService.findAll();
		Long chOO1=0l;
		Long chOO2=0l;
		wrapper.orderBy("id",false);
		if(is==4){

			page = bookOrderService.selectPage(getPage(BookOrderDO.class), wrapper);

		}else if(is==3){
			page = bookOrderService.selectPage(getPage(BookOrderDO.class)
					, wrapper);

		}else if(is==2){
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		else if(is==1){
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		else if(is==5){
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		//市场一部管理员
		else if(is==6){
			List lists=new ArrayList();
			List list=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场一部")||roleDO.getRoleName().equals("市场一部管理员")){
					chOO1=roleDO.getId();
					lists.add(chOO1);
					//break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.in("roleId",lists);

			Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);

			List<UserRoleDO> userRoleDOS=	page1.getRecords();
			for(UserRoleDO users:userRoleDOS){
				list.add(users.getUserId());
			}

			wrapper.in("creare_user",list);
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		//市场二部管理员
		else if(is==7){
			List list=new ArrayList();
			List lists=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场二部")||roleDO.getRoleName().equals("市场二部管理员")){
					chOO2=roleDO.getId();
					lists.add(chOO2);
					//break;
				}
			}

			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			//wrapper1.eq("roleId",chOO2);
			wrapper1.in("roleId",lists);

			Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);

			List<UserRoleDO> userRoleDOS=	page1.getRecords();
			for(UserRoleDO users:userRoleDOS){
				list.add(users.getUserId());
			}

			wrapper.in("creare_user",list);
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		//市场一部
		else if(is==8){
			wrapper.eq("creare_user",this.getUserId() );
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}
		//市场二部
		else if(is==9){
			wrapper.eq("creare_user",this.getUserId() );
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}else if(is==10){
			page = bookOrderService.selectPage(getPage(BookOrderDO.class),
					wrapper);
		}else if(is==11){
			page = bookOrderService.selectPage(getPage(BookOrderDO.class), wrapper);
		}


		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
			BookOrderDO obj = (BookOrderDO) page.getRecords().get(i);
			BookOrderVO bookOrderVO=new BookOrderVO();
			bookOrderVO.setCounty(obj.getCounty());
			bookOrderVO.setAddress(obj.getAddress());
			if(obj.getOrderCreatetime()!=null){
				bookOrderVO.setOrderCreatetimes(sdfs.format(obj.getOrderCreatetime()));
			}

			bookOrderVO.setCity(obj.getCity());
			bookOrderVO.setDiscount(obj.getDiscount());
			bookOrderVO.setGoodsUser(obj.getGoodsUser());
			bookOrderVO.setAdminRemarks(obj.getAdminRemarks());
			bookOrderVO.setWarehouse(obj.getWarehouse());
			bookOrderVO.setState(obj.getState());
			bookOrderVO.setProvince(obj.getProvince());
			bookOrderVO.setOrderUser(obj.getOrderUser());
			bookOrderVO.setRemarks(obj.getRemarks());
			bookOrderVO.setOrderNumber(obj.getOrderNumber());
			bookOrderVO.setOrderMoney(obj.getOrderMoney());
			bookOrderVO.setMobile(obj.getMobile());
			bookOrderVO.setId(obj.getId());
			bookOrderVO.setOrderPrimary(obj.getOrderPrimary());
			bookOrderVO.setOrderSenior(obj.getOrderSenior());
			bookOrderVO.setOrderIntermediate(obj.getOrderIntermediate());
			bookOrderVO.setInvoiceAddress(obj.getInvoiceAddress());
			bookOrderVO.setPost(obj.getPost());
			bookOrderVO.setInvoiceType(obj.getInvoiceType());
			bookOrderVO.setStateCollection(obj.getStateCollection());
			bookOrderVO.setOrderCode(obj.getOrderCode());
			bookOrderVO.setYear(obj.getYear());
			bookOrderVO.setExpressName(obj.getExpressName());
			//计算原价
			BigDecimal bigDecimalYuanJia=new BigDecimal(0);

			bookOrderVO.setDepartment(department);
			//折扣跟订单数量
			//计算基础知识折扣价格
			BigDecimal money=	BigDecimal.valueOf(obj.getOrderNumber());
			//初级价格
			BigDecimal money1=	BigDecimal.valueOf(obj.getOrderPrimary());
			//中级价格
			BigDecimal money2=	BigDecimal.valueOf(obj.getOrderIntermediate());
			//高级价格
			BigDecimal money3=	BigDecimal.valueOf(obj.getOrderSenior());

			BigDecimal orderMoney1=new BigDecimal(0);
			BigDecimal orderMoney2=new BigDecimal(0);
			BigDecimal orderMoney3=new BigDecimal(0);
			BigDecimal orderMoney4=new BigDecimal(0);

			Wrapper<BookStockDO> wrapper1s = new EntityWrapper();
			wrapper1s.eq("book_types", obj.getBookId());
			//查询价格
			List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper1s);


			for(BookStockDO bookm:bookPurchaseDO){
				if(bookm.getBookType().indexOf("基础知识")!=-1){
					orderMoney1=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("初级")!=-1){
					orderMoney2=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("中级")!=-1){
					orderMoney3=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("高级")!=-1){
					orderMoney4=bookm.getMoney();
				}
			}
			//计算基础知识价格
			BigDecimal orderMoney=(money.multiply(orderMoney1));

			//计算初级价格
			BigDecimal orderMoneys1=(money1.multiply(orderMoney2));

			//计算中级价格
			BigDecimal orderMoneys2=(money2.multiply(orderMoney3));

			//计算高级价格
			BigDecimal orderMoneys3=(money3.multiply(orderMoney4));

			bigDecimalYuanJia=orderMoney.add(orderMoneys1).add(orderMoneys2).add(orderMoneys3);
			//原价
			bookOrderVO.setPrimaryMoney(bigDecimalYuanJia);

			UserDO userDO=userService.selectById(obj.getCreareUser());
			if(userDO!=null){
				bookOrderVO.setCreateUserNmae(userDO.getName());
			}

			UserDO userDO1=userService.selectById(obj.getOrderUser());
			if(userDO1!=null){
				bookOrderVO.setOrderUserName(userDO1.getName());
			}
			UserDO userDO2=userService.selectById(obj.getGoodsUser());
			if(userDO2!=null){
				bookOrderVO.setGoodsUserName(userDO2.getName());
			}
			//书籍名称
			//if(bookStockDO!=null){
			bookOrderVO.setBookName(obj.getBookId());
			//}
			bookOrderVO.setSchool(obj.getSchool());
			bookOrderVO.setActualMoney(obj.getActualMoney());
			bookOrderVO.setWarehouse(obj.getWarehouse());
			bookOrderVO.setBillingAccountNumber(obj.getBillingAccountNumber());
			bookOrderVO.setBillingAddress(obj.getBillingAddress());
			bookOrderVO.setBillingMailbox(obj.getBillingMailbox());
			bookOrderVO.setBillingAccountNumber(obj.getBillingAccountNumber());
			bookOrderVO.setBillingNumber(obj.getBillingNumber());
			bookOrderVO.setStateMoney(obj.getStateMoney());
			bookOrderVO.setStateMoneyMark(obj.getStateMoneyMark());
			bookOrderVO.setAddressee(obj.getAddressee());
			bookOrderVO.setBillingName(obj.getBillingName());
			bookOrderVO.setRefundMoney(obj.getRefundMoney());
			bookOrderVO.setRefundState(obj.getRefundState());
			bookOrderVO.setDiscountSenior(obj.getDiscountSenior());
			bookOrderVO.setDiscountIntermediate(obj.getDiscountIntermediate());
			bookOrderVO.setDiscountPrimary(obj.getDiscountPrimary());
			bookOrderVO.setExlUrl(obj.getExlUrl());//primaryDiscountPayment


			//基础知识
			bookOrderVO.setBasicsPayment(obj.getBasicsPayment());
			//初级折扣价
			bookOrderVO.setPrimaryDiscountPayment(obj.getPrimaryDiscountPayment());
			//中级折扣价
			bookOrderVO.setIntermediatePayment(obj.getIntermediatePayment());
			//高级折扣价
			bookOrderVO.setSeniorPayment(obj.getSeniorPayment());
			bookOrderVO.setDepartment(obj.getDepartment());
			list.add(bookOrderVO);
		}
		page.setRecords(list);
		return Result.ok(page);
	}

	/**
	 * 判断是否有数据
	 */
	@Log("判断是否有数据")
	@RequestMapping("/isDataNull")
	@ResponseBody
	public boolean isDataNull(HttpServletRequest request, HttpServletResponse response,BookOrderVO bookOrderDTO) throws Exception{


			return true;
	}


	@GetMapping("/orderExportList")
	@ResponseBody
	@Transactional
	@RequiresPermissions("jzweb:bookOrder:export")
	public void exportlist(HttpServletRequest request, HttpServletResponse response, BookOrderVO bookOrderDTO) throws Exception{
		// 查询列表数据
		int is=0;
		Long roleId=0l;
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//查询所有用户所属权限
		List<String> organizationNewsDOS = userRoleService.selroleNameList(this.getUserId());

		//for(RoleDO li:listRole){
		for(String name:organizationNewsDOS){

			if(name.equals("订单审核专员")){
				is=2;
			}else if(name.equals("订单发布专员")){
				is=1;
			}else if(name.equals("金职仓库审核专员")){
				is=3;
			}else if(name.equals("超级用户角色")){
				is=4;
				break;
			}else if(name.equals("金英仓库审核专员")){
				is=5;
			}else if(name.equals("市场一部管理员")){
				is=6;
			}else if(name.equals("市场二部管理员")){
				is=7;
			}else if(name.equals("市场一部")){
				is=8;
			}else if(name.equals("市场二部")){
				is=9;
			}else if(name.equals("财务审核发票")){
				is=10;
			}else if(name.equals("管理员")){
				is=11;
			}
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		List<BookOrderDO> page =null;
		EntityWrapper<BookOrderDO> wrapper = new EntityWrapper<>();

		if(bookOrderDTO.getState()!=null){
			wrapper.eq("state",bookOrderDTO.getState() );
		}

		if(bookOrderDTO.getProvince()!=null&&bookOrderDTO.getProvince()!=""){
			wrapper.like("province", bookOrderDTO.getProvince());
		}

		if(bookOrderDTO.getStateMoney()!=null){
			wrapper.like("state_money", bookOrderDTO.getStateMoney().toString());
		}

		if(bookOrderDTO.getRefundState()!=null){
			wrapper.like("refund_state", bookOrderDTO.getRefundState().toString());
		}


		if(StringUtils.isNotBlank(bookOrderDTO.getStartTime())){
			Date format = null;
			try {
				format = sdf.parse(bookOrderDTO.getStartTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			wrapper.ge("order_createtime",format);

		}

		if(bookOrderDTO.getYear()!=null){
			wrapper.eq("year",bookOrderDTO.getYear());
		}

		wrapper.eq("order_type",bookOrderDTO.getOrderType());

		if(StringUtils.isNotBlank(bookOrderDTO.getEndTime())){
			Date format = null;
			try {
				format = sdf.parse(bookOrderDTO.getEndTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			wrapper.le("order_createtime",format);

		}

		List<RoleDO>  listRole=roleService.findAll();
		Long chOO1=0l;
		Long chOO2=0l;
		wrapper.orderBy("id",false);
		if(is==4){

			page = bookOrderService.selectList(wrapper);

		}else if(is==3){
			page = bookOrderService.selectList(wrapper);

		}else if(is==11){
			page = bookOrderService.selectList(wrapper);

		}else if(is==2){
			page = bookOrderService.selectList(wrapper);
		}
		else if(is==1){
			page = bookOrderService.selectList(wrapper);
		}
		else if(is==5){
			page = bookOrderService.selectList(wrapper);
		}
		//市场一部管理员
		else if(is==6){
			List list=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场一部")){
					chOO1=roleDO.getId();
					break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.eq("roleId",chOO1);

			Page<UserRoleDO> page1 =	userRoleService.selectPage(getPage(UserRoleDO.class), wrapper1);

			List<UserRoleDO> userRoleDOS=	page1.getRecords();
			for(UserRoleDO users:userRoleDOS){
				list.add(users.getUserId());
			}

			wrapper.in("creare_user",list);
			page = bookOrderService.selectList(wrapper);
		}
		//市场二部管理员
		else if(is==7){
			List list=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场二部")){
					chOO2=roleDO.getId();
					break;
				}
			}

			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.eq("roleId",chOO2);

			Page<UserRoleDO> page1 =	userRoleService.selectPage(getPage(UserRoleDO.class), wrapper1);

			List<UserRoleDO> userRoleDOS=	page1.getRecords();
			for(UserRoleDO users:userRoleDOS){
				list.add(users.getUserId());
			}

			wrapper.in("creare_user",list);
			page = bookOrderService.selectList(wrapper);
		}
		//市场一部
		else if(is==8){
			wrapper.eq("creare_user",this.getUserId() );
			page = bookOrderService.selectList(wrapper);
		}
		//市场二部
		else if(is==9){
			wrapper.eq("creare_user",this.getUserId() );
			page = bookOrderService.selectList(wrapper);
		}else if(is==10){
			page = bookOrderService.selectList(wrapper);
		}


		List<BookOrderVO> list = new ArrayList();
		for (int i = 0; i < page.size(); i++) {
			BookOrderDO obj = (BookOrderDO) page.get(i);
			BookOrderVO bookOrderVO=new BookOrderVO();
			bookOrderVO.setCounty(obj.getCounty());
			bookOrderVO.setAddress(obj.getAddress());

			bookOrderVO.setOrderCreatetime(obj.getOrderCreatetime());

			bookOrderVO.setCity(obj.getCity());
			bookOrderVO.setDiscount(obj.getDiscount());
			bookOrderVO.setGoodsUser(obj.getGoodsUser());
			bookOrderVO.setAdminRemarks(obj.getAdminRemarks());
			bookOrderVO.setWarehouse(obj.getWarehouse());
			bookOrderVO.setState(obj.getState());
			bookOrderVO.setProvince(obj.getProvince());
			bookOrderVO.setOrderUser(obj.getOrderUser());
			bookOrderVO.setRemarks(obj.getRemarks());
			bookOrderVO.setOrderNumber(obj.getOrderNumber());
			bookOrderVO.setOrderMoney(obj.getOrderMoney());
			bookOrderVO.setMobile(obj.getMobile());
			bookOrderVO.setId(obj.getId());
			bookOrderVO.setOrderPrimary(obj.getOrderPrimary());
			bookOrderVO.setOrderSenior(obj.getOrderSenior());
			bookOrderVO.setOrderIntermediate(obj.getOrderIntermediate());


			bookOrderVO.setInvoiceAddress(obj.getInvoiceAddress());
			bookOrderVO.setPost(obj.getPost());
			bookOrderVO.setInvoiceType(obj.getInvoiceType());
			bookOrderVO.setStateCollection(obj.getStateCollection());
			bookOrderVO.setOrderCode(obj.getOrderCode());
			bookOrderVO.setExpressName(obj.getExpressName());
			//计算原价
			BigDecimal bigDecimalYuanJia=new BigDecimal(0);

			//折扣跟订单数量
			//计算基础知识折扣价格
			BigDecimal money=	BigDecimal.valueOf(obj.getOrderNumber());
			//初级价格
			BigDecimal money1=	BigDecimal.valueOf(obj.getOrderPrimary());
			//中级价格
			BigDecimal money2=	BigDecimal.valueOf(obj.getOrderIntermediate());
			//高级价格
			BigDecimal money3=	BigDecimal.valueOf(obj.getOrderSenior());

			BigDecimal orderMoney1=new BigDecimal(0);
			BigDecimal orderMoney2=new BigDecimal(0);
			BigDecimal orderMoney3=new BigDecimal(0);
			BigDecimal orderMoney4=new BigDecimal(0);

			Wrapper<BookStockDO> wrapper1s = new EntityWrapper();
			wrapper1s.eq("book_types", obj.getBookId());
			//查询价格
			List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper1s);


			for(BookStockDO bookm:bookPurchaseDO){
				if(bookm.getBookType().indexOf("基础知识")!=-1){
					orderMoney1=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("初级")!=-1){
					orderMoney2=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("中级")!=-1){
					orderMoney3=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("高级")!=-1){
					orderMoney4=bookm.getMoney();
				}
			}
			//计算基础知识价格
			BigDecimal orderMoney=(money.multiply(orderMoney1));

			//计算初级价格
			BigDecimal orderMoneys1=(money1.multiply(orderMoney2));

			//计算中级价格
			BigDecimal orderMoneys2=(money2.multiply(orderMoney3));

			//计算高级价格
			BigDecimal orderMoneys3=(money3.multiply(orderMoney4));

			bigDecimalYuanJia=orderMoney.add(orderMoneys1).add(orderMoneys2).add(orderMoneys3);
			bookOrderVO.setPrimaryMoney(bigDecimalYuanJia);

			UserDO userDO=userService.selectById(obj.getCreareUser());
			if(userDO!=null){
				bookOrderVO.setCreateUserNmae(userDO.getName());
			}

			UserDO userDO1=userService.selectById(obj.getOrderUser());
			if(userDO1!=null){
				bookOrderVO.setOrderUserName(userDO1.getName());
			}
			UserDO userDO2=userService.selectById(obj.getGoodsUser());
			if(userDO2!=null){
				bookOrderVO.setGoodsUserName(userDO2.getName());
			}
			//书籍名称
			//if(bookStockDO!=null){
			bookOrderVO.setBookName(obj.getBookId());
			//}
			bookOrderVO.setSchool(obj.getSchool());
			bookOrderVO.setActualMoney(obj.getActualMoney());
			bookOrderVO.setWarehouse(obj.getWarehouse());
			bookOrderVO.setBillingAccountNumber(obj.getBillingAccountNumber());
			bookOrderVO.setBillingAddress(obj.getBillingAddress());
			bookOrderVO.setBillingMailbox(obj.getBillingMailbox());
			bookOrderVO.setBillingNumber(obj.getBillingNumber());
			bookOrderVO.setStateMoney(obj.getStateMoney());
			bookOrderVO.setStateMoneyMark(obj.getStateMoneyMark());
			bookOrderVO.setAddressee(obj.getAddressee());
			bookOrderVO.setStartTime(sdf.format(obj.getOrderCreatetime()));
			bookOrderVO.setBillingName(obj.getBillingName());
			bookOrderVO.setRefundMoney(obj.getRefundMoney());
			bookOrderVO.setRefundState(obj.getRefundState());
			bookOrderVO.setDiscountSenior(obj.getDiscountSenior());
			bookOrderVO.setDiscountIntermediate(obj.getDiscountIntermediate());
			bookOrderVO.setDiscountPrimary(obj.getDiscountPrimary());
			bookOrderVO.setExlUrl(obj.getExlUrl());

			//基础知识
			bookOrderVO.setBasicsPayment(obj.getBasicsPayment());
			//初级折扣价
			bookOrderVO.setPrimaryDiscountPayment(obj.getPrimaryDiscountPayment());
			//中级折扣价
			bookOrderVO.setIntermediatePayment(obj.getIntermediatePayment());
			//高级折扣价
			bookOrderVO.setSeniorPayment(obj.getSeniorPayment());
			//refundStates
			if(bookOrderVO.getRefundState()==0){
				bookOrderVO.setRefundStates("未退款");
			}else if(bookOrderVO.getRefundState()==1){
				bookOrderVO.setRefundStates("已退款");
			}else {
				bookOrderVO.setRefundStates("未退款");
			}


			if(obj.getState()==0){
				bookOrderVO.setStates("未审核");
			}else if(obj.getState()==1){
				bookOrderVO.setStates("订单审核通过");
			}else if(obj.getState()==2){
				bookOrderVO.setStates("订单审核拒绝");
			}else if(obj.getState()==3){
				bookOrderVO.setStates("仓库审核通过");
			}else if(obj.getState()==4){
				bookOrderVO.setStates("仓库审核拒绝");
			}else {
				bookOrderVO.setStates("未审核");
			}
			if(obj.getStateCollection()==0){
				bookOrderVO.setStateCollections("未付款");
			}else if(obj.getStateCollection()==1){
				bookOrderVO.setStateCollections("已付款");
			}else {
				bookOrderVO.setStateCollections("未付款");
			}

			if(obj.getPost()==0){
				bookOrderVO.setPosts("包邮");
			}else {
				bookOrderVO.setPosts("不包邮");
			}

			if(obj.getStateMoney()==2){
				bookOrderVO.setStateMoneys("未开票");
			}else if(obj.getStateMoney()==3){
				bookOrderVO.setStateMoneys("已开票");
			}else {
				bookOrderVO.setStateMoneys("未开票");
			}

			list.add(bookOrderVO);
		}
		String name="";
		if(bookOrderDTO.getYear()==null){
			name="其他订单";
		}else {
			name=bookOrderDTO.getYear().toString();
		}
		EasyPoiUtil.exportExcel(list, "订单记录", "订单记录", BookOrderVO.class,"书籍订单记录表"+name, response);
	}

	/**
	 * 新增
	 * @param model
	 * @return
	 */
	@GetMapping("/add1")
	@RequiresPermissions("jzweb:bookOrder:add")
	String add1(Model model){
		Map map=new HashMap();
		List<BookStockDO> list=bookStockService.list(map);
		List <Map> mapList=new ArrayList<>();

		Map map1=new HashMap();
		map1.put("name","幼儿照护");
		mapList.add(map1);
		Map map2=new HashMap();
		map2.put("name","产后恢复");
		mapList.add(map2);
		model.addAttribute("list2",mapList);
		model.addAttribute("list",list);

		return "jzweb/bookOrder/add1";
	}
	/**
	 * 2020年新增
	 * @param model
	 * @return
	 */
	@GetMapping("/add2020")
	@RequiresPermissions("jzweb:bookOrder:add")
	String add2020(Model model){
		Map map=new HashMap();
		List<BookStockDO> list=bookStockService.list(map);
		List <Map> mapList=new ArrayList<>();

		Map map1=new HashMap();
		map1.put("name","幼儿照护");
		mapList.add(map1);
		Map map2=new HashMap();
		map2.put("name","产后恢复");
		mapList.add(map2);
		model.addAttribute("list2",mapList);
		model.addAttribute("list",list);

		return "jzweb/bookOrder/add2020";
	}
	@GetMapping("/add")
	@RequiresPermissions("jzweb:bookOrder:add")
	String add(Model model){
		Map map=new HashMap();
		List<BookStockDO> list=bookStockService.list(map);
		List <Map> mapList=new ArrayList<>();

			Map map1=new HashMap();
			map1.put("name","幼儿照护");
		mapList.add(map1);
		Map map2=new HashMap();
		map2.put("name","产后恢复");
		mapList.add(map2);
		model.addAttribute("list2",mapList);
		model.addAttribute("list",list);

	    return "jzweb/bookOrder/add";
	}

	@GetMapping("/examine/{id}")
	@RequiresPermissions("jzweb:bookOrder:examine")
	String examine(@PathVariable("id") Long id,Model model ){
		BookOrderDO bookOrder = bookOrderService.selectById(id);
		Map map=new HashMap();
//		List<BookStockDO> list=bookStockService.list(map);
//		model.addAttribute("list",list);

		List<Map> list=bookStockService.listWarehouse(map);

		model.addAttribute("bookOrder", bookOrder);
		model.addAttribute("list", list);


	    return "jzweb/bookOrder/examine";
	}

	/**
	 * 部门主管审核订单
	 * @param id
	 * @param model
	 * @return
	 */
	@GetMapping("/editZG/{id}")
	@RequiresPermissions("jzweb:bookOrder:editZG")
	String editZG(@PathVariable("id") Long id,Model model ){
		BookOrderDO bookOrder = bookOrderService.selectById(id);
		Map map=new HashMap();
//		List<BookStockDO> list=bookStockService.list(map);
//		model.addAttribute("list",list);

		List<Map> list=bookStockService.listWarehouse(map);

		model.addAttribute("bookOrder", bookOrder);
		model.addAttribute("list", list);


		return "jzweb/bookOrder/editCw1";
	}

	/**
	 * 财务审核
	 * @param id
	 * @param model
	 * @return
	 */
	@GetMapping("/editCw/{id}")
	@RequiresPermissions("jzweb:bookOrder:editCw")
	String editCw(@PathVariable("id") Long id,Model model ){
		BookOrderDO bookOrder = bookOrderService.selectById(id);
		Map map=new HashMap();
//		List<BookStockDO> list=bookStockService.list(map);
//		model.addAttribute("list",list);

		List<Map> list=bookStockService.listWarehouse(map);

		model.addAttribute("bookOrder", bookOrder);
		model.addAttribute("list", list);


		return "jzweb/bookOrder/editCw";
	}

	/**
	 * 查看订单详情
	 * @param id
	 * @param model
	 * @return
	 */
	@GetMapping("/examineDetails/{id}")
	@RequiresPermissions("jzweb:bookOrder:examineDetails")
	String examineDetails(@PathVariable("id") Long id,Model model ){
		BookOrderDO bookOrder = bookOrderService.selectById(id);
		Map map=new HashMap();

		List<Map> list=bookStockService.listWarehouse(map);
		List <Map> mapList=new ArrayList<>();

		Map map1=new HashMap();
		map1.put("name","幼儿照护");
		mapList.add(map1);
		Map map2=new HashMap();
		map2.put("name","产后恢复");
		mapList.add(map2);
		model.addAttribute("list2",mapList);
		if(bookOrder!=null){


		BookOrderDO obj =  bookOrder;
		BookOrderVO bookOrderVO=new BookOrderVO();
		bookOrderVO.setCounty(obj.getCounty());
		bookOrderVO.setAddress(obj.getAddress());
		bookOrderVO.setOrderCreatetime(obj.getOrderCreatetime());
		bookOrderVO.setCity(obj.getCity());
		bookOrderVO.setDiscount(obj.getDiscount());
		bookOrderVO.setGoodsUser(obj.getGoodsUser());
		bookOrderVO.setAdminRemarks(obj.getAdminRemarks());
		bookOrderVO.setWarehouse(obj.getWarehouse());
		bookOrderVO.setState(obj.getState());
		bookOrderVO.setProvince(obj.getProvince());
		bookOrderVO.setOrderUser(obj.getOrderUser());
		bookOrderVO.setRemarks(obj.getRemarks());
		bookOrderVO.setOrderNumber(obj.getOrderNumber());
		bookOrderVO.setOrderMoney(obj.getOrderMoney());
		bookOrderVO.setMobile(obj.getMobile());
		bookOrderVO.setId(obj.getId());
		bookOrderVO.setOrderPrimary(obj.getOrderPrimary());
		bookOrderVO.setOrderSenior(obj.getOrderSenior());
		bookOrderVO.setOrderIntermediate(obj.getOrderIntermediate());


		bookOrderVO.setInvoiceAddress(obj.getInvoiceAddress());
		bookOrderVO.setPost(obj.getPost());
		bookOrderVO.setInvoiceType(obj.getInvoiceType());
		bookOrderVO.setStateCollection(obj.getStateCollection());
		bookOrderVO.setOrderCode(obj.getOrderCode());
			bookOrderVO.setExpressName(obj.getExpressName());
			//计算原价
			BigDecimal bigDecimalYuanJia=new BigDecimal(0);

			//折扣跟订单数量
			//计算基础知识折扣价格
			BigDecimal money=	BigDecimal.valueOf(obj.getOrderNumber());
			//初级价格
			BigDecimal money1=	BigDecimal.valueOf(obj.getOrderPrimary());
			//中级价格
			BigDecimal money2=	BigDecimal.valueOf(obj.getOrderIntermediate());
			//高级价格
			BigDecimal money3=	BigDecimal.valueOf(obj.getOrderSenior());

			BigDecimal orderMoney1=new BigDecimal(0);
			BigDecimal orderMoney2=new BigDecimal(0);
			BigDecimal orderMoney3=new BigDecimal(0);
			BigDecimal orderMoney4=new BigDecimal(0);

			Wrapper<BookStockDO> wrapper1s = new EntityWrapper();
			wrapper1s.eq("book_types", obj.getBookId());
			//查询价格
			List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper1s);


			for(BookStockDO bookm:bookPurchaseDO){
				if(bookm.getBookType().indexOf("基础知识")!=-1){
					orderMoney1=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("初级")!=-1){
					orderMoney2=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("中级")!=-1){
					orderMoney3=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("高级")!=-1){
					orderMoney4=bookm.getMoney();
				}
			}
//			//计算基础知识价格
//			BigDecimal orderMoney=(money.multiply(orderMoney1)).multiply(obj.getDiscount().divide(new BigDecimal(10),2));
//
//			//计算初级价格
//			BigDecimal orderMoneys1=(money1.multiply(orderMoney2)).multiply(obj.getDiscountPrimary().divide(new BigDecimal(10),2));
//
//			//计算中级价格
//			BigDecimal orderMoneys2=(money2.multiply(orderMoney3)).multiply(obj.getDiscountIntermediate().divide(new BigDecimal(10),2));
//
//			//计算高级价格
//			BigDecimal orderMoneys3=(money3.multiply(orderMoney4)).multiply(obj.getDiscountSenior().divide(new BigDecimal(10),2));
//
//			bigDecimalYuanJia=orderMoney.add(orderMoneys1).add(orderMoneys1).add(orderMoneys2).add(orderMoneys3);
//
//			bookOrderVO.setPrimaryMoney(bigDecimalYuanJia);

		//bookOrderVO.setPrimaryMoney(obj.getOrderMoney().divide((obj.getDiscount().divide(new BigDecimal(10)))));

		UserDO userDO=userService.selectById(obj.getCreareUser());
		if(userDO!=null){
			bookOrderVO.setCreateUserNmae(userDO.getName());
		}

		UserDO userDO1=userService.selectById(obj.getOrderUser());
		if(userDO1!=null){
			bookOrderVO.setOrderUserName(userDO1.getName());
		}
		UserDO userDO2=userService.selectById(obj.getGoodsUser());
		if(userDO2!=null){
			bookOrderVO.setGoodsUserName(userDO2.getName());
		}
		//书籍名称
		//if(bookStockDO!=null){
		bookOrderVO.setBookName(obj.getBookId());
		//}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		bookOrderVO.setSchool(obj.getSchool());
			bookOrderVO.setExlUrl(obj.getExlUrl());
		bookOrderVO.setActualMoney(obj.getActualMoney());
		bookOrderVO.setWarehouse(obj.getWarehouse());
		bookOrderVO.setBillingAccountNumber(obj.getBillingAccountNumber());
		bookOrderVO.setBillingAddress(obj.getBillingAddress());
		bookOrderVO.setBillingMailbox(obj.getBillingMailbox());
		bookOrderVO.setBillingAccountNumber(obj.getBillingAccountNumber());
		bookOrderVO.setBillingNumber(obj.getBillingNumber());
		bookOrderVO.setStateMoney(obj.getStateMoney());
		bookOrderVO.setStateMoneyMark(obj.getStateMoneyMark());
		bookOrderVO.setAddressee(obj.getAddressee());
		bookOrderVO.setStartTime(sdf.format(obj.getOrderCreatetime()));
		bookOrderVO.setBillingName(obj.getBillingName());
		bookOrderVO.setRefundMoney(obj.getRefundMoney());
		bookOrderVO.setRefundState(obj.getRefundState());
		bookOrderVO.setDiscountSenior(obj.getDiscountSenior());
		bookOrderVO.setDiscountIntermediate(obj.getDiscountIntermediate());
		bookOrderVO.setDiscountPrimary(obj.getDiscountPrimary());
		//refundStates
		if(bookOrderVO.getRefundState()==0){
			bookOrderVO.setRefundStates("未退款");
		}else if(bookOrderVO.getRefundState()==1){
			bookOrderVO.setRefundStates("已退款");
		}else {
			bookOrderVO.setRefundStates("未退款");
		}


		if(obj.getState()==0){
			bookOrderVO.setStates("未审核");
		}else if(obj.getState()==1){
			bookOrderVO.setStates("订单审核通过");
		}else if(obj.getState()==2){
			bookOrderVO.setStates("订单审核拒绝");
		}else if(obj.getState()==3){
			bookOrderVO.setStates("仓库审核通过");
		}else if(obj.getState()==4){
			bookOrderVO.setStates("仓库审核拒绝");
		}else {
			bookOrderVO.setStates("未审核");
		}
		if(obj.getStateCollection()==0){
			bookOrderVO.setStateCollections("未付款");
		}else if(obj.getStateCollection()==1){
			bookOrderVO.setStateCollections("已付款");
		}else {
			bookOrderVO.setStateCollections("未付款");
		}

		if(obj.getPost()==0){
			bookOrderVO.setPosts("包邮");
		}else {
			bookOrderVO.setPosts("不包邮");
		}

		if(obj.getStateMoney()==2){
			bookOrderVO.setStateMoneys("未开票");
		}else if(obj.getStateMoney()==3){
			bookOrderVO.setStateMoneys("已开票");
		}else {
			bookOrderVO.setStateMoneys("未开票");
		}
			//折扣跟订单数量
			//计算基础知识折扣价格
//			BigDecimal money=	BigDecimal.valueOf(bookOrder.getOrderNumber());
//			//初级价格
//			BigDecimal money1=	BigDecimal.valueOf(bookOrder.getOrderPrimary());
//			//中级价格
//			BigDecimal money2=	BigDecimal.valueOf(bookOrder.getOrderIntermediate());
//			//高级价格
//			BigDecimal money3=	BigDecimal.valueOf(bookOrder.getOrderSenior());
//
//			BigDecimal orderMoney1=new BigDecimal(0);
//			BigDecimal orderMoney2=new BigDecimal(0);
//			BigDecimal orderMoney3=new BigDecimal(0);
//			BigDecimal orderMoney4=new BigDecimal(0);

//			Wrapper<BookStockDO> wrapper = new EntityWrapper();
//			wrapper.eq("book_types", bookOrder.getBookId());
//			//查询价格
//			List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper);
//

			for(BookStockDO bookm:bookPurchaseDO){
				if(bookm.getBookType().indexOf("基础知识")!=-1){
					orderMoney1=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("初级")!=-1){
					orderMoney2=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("中级")!=-1){
					orderMoney3=bookm.getMoney();
				}else if(bookm.getBookType().indexOf("高级")!=-1){
					orderMoney4=bookm.getMoney();
				}
			}
			//计算基础知识价格
			BigDecimal orderMoneyY=(money.multiply(orderMoney1));

			//计算初级价格
			BigDecimal orderMoneys1Y=(money1.multiply(orderMoney2));

			//计算中级价格
			BigDecimal orderMoneys2Y=(money2.multiply(orderMoney3));

			//计算高级价格
			BigDecimal orderMoneys3Y=(money3.multiply(orderMoney4));

			BigDecimal orderSumMoney=new BigDecimal(0);
			orderSumMoney=orderMoneyY.add(orderMoneys1Y).add(orderMoneys2Y).add(orderMoneys3Y);

			bookOrderVO.setPrimaryMoney(orderSumMoney);

			bookOrder.setOrderMoney(orderSumMoney);

			model.addAttribute("bookOrder", bookOrderVO);
		}

		model.addAttribute("list", list);


		return "jzweb/bookOrder/editDetails";
	}
	/**
	 * 编辑
	 * @param id
	 * @param model
	 * @return
	 */
	@GetMapping("/edit1/{id}")
	@RequiresPermissions("jzweb:bookOrder:edit")
	String edit1(@PathVariable("id") Long id,Model model){
		BookOrderDO bookOrder = bookOrderService.selectById(id);
		Map map=new HashMap();
		List<BookStockDO> list=bookStockService.list(map);
		model.addAttribute("list",list);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		bookOrder.setOrderCreatetimeS(sdf.format(bookOrder.getOrderCreatetime()));

		model.addAttribute("bookOrder", bookOrder);
		List <Map> mapList=new ArrayList<>();

		Map map1=new HashMap();
		map1.put("name","幼儿照护");
		mapList.add(map1);
		Map map2=new HashMap();
		map2.put("name","产后恢复");
		mapList.add(map2);
		model.addAttribute("list2", mapList);
		return "jzweb/bookOrder/edit1";
	}
	/**
	 * 编辑
	 * @param id
	 * @param model
	 * @return
	 */
	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:bookOrder:edit")
	String edit(@PathVariable("id") Long id,Model model){
		BookOrderDO bookOrder = bookOrderService.selectById(id);
		Map map=new HashMap();
		List<BookStockDO> list=bookStockService.list(map);
		model.addAttribute("list",list);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		bookOrder.setOrderCreatetimeS(sdf.format(bookOrder.getOrderCreatetime()));

		model.addAttribute("bookOrder", bookOrder);
		List <Map> mapList=new ArrayList<>();

		Map map1=new HashMap();
		map1.put("name","幼儿照护");
		mapList.add(map1);
		Map map2=new HashMap();
		map2.put("name","产后恢复");
		mapList.add(map2);
		model.addAttribute("list2", mapList);
		return "jzweb/bookOrder/edit";
	}

	/**
	 * 这里计算订单价格
	 * @param bookOrder
	 *
	 * @param district
	 * @return
	 */
	@Log("添加订单记录表")
	@ResponseBody
	@PostMapping("/save1")
	@RequiresPermissions("jzweb:bookOrder:add")
	public Result<String> save1( BookOrderDO bookOrder,String district){
		if(bookOrder.getBookId()==null){
			return Result.fail("请选择书籍种类！");
		}

		if(bookOrder.getOrderCreatetime()==null){
			return Result.fail("请选择订单创建时间！");
		}
		Wrapper<BookStockDO> wrapper = new EntityWrapper();
		wrapper.eq("book_types", bookOrder.getBookId());
		//查询价格
		List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper);
		//查询学校名称是否存在并且不能为空

		if(!StringUtil.notEmpty(bookOrder.getSchool())){
			return Result.fail("学校名称不能为空或者系统中不存在！");
		}
		Page<Map<Object,Object>> listSchool=bookOrderService.selectSchool(1,10,bookOrder.getSchool());
		if(listSchool.getRecords().size()==0){
			return Result.fail("学校名称系统不存在！");
		}

		if(bookPurchaseDO.size()==0){
			return Result.fail("订单价格出现异常，请联系管理员！");
		}
		bookOrder.setOrderType(1);
		//bookOrder.setOrderCreatetime(new Date());
		bookOrder.setCreareUser(this.getUserId());
		bookOrder.setCounty(district);
		bookOrder.setDiscount(new BigDecimal(10));
		bookOrder.setDiscountIntermediate(new BigDecimal(10));
		bookOrder.setDiscountPrimary(new BigDecimal(10));
		bookOrder.setDiscountSenior(new BigDecimal(10));
//		if(bookOrder.getDiscount().compareTo(new BigDecimal(10))>0){
//			return Result.fail("折扣不能大于10");
//		}
//		if(bookOrder.getDiscountIntermediate().compareTo(new BigDecimal(10))>0){
//			return Result.fail("折扣不能大于10");
//		}
//		if(bookOrder.getDiscountPrimary().compareTo(new BigDecimal(10))>0){
//			return Result.fail("折扣不能大于10");
//		}
//		if(bookOrder.getDiscountSenior().compareTo(new BigDecimal(10))>0){
//			return Result.fail("折扣不能大于10");
//		}

		//折扣跟订单数量
		//计算基础知识折扣价格
		BigDecimal money=	BigDecimal.valueOf(bookOrder.getOrderNumber());
		//初级价格
		BigDecimal money1=	BigDecimal.valueOf(bookOrder.getOrderPrimary());
		//中级价格
		BigDecimal money2=	BigDecimal.valueOf(bookOrder.getOrderIntermediate());
		//高级价格
		BigDecimal money3=	BigDecimal.valueOf(bookOrder.getOrderSenior());

		BigDecimal orderMoney1=new BigDecimal(0);
		BigDecimal orderMoney2=new BigDecimal(0);
		BigDecimal orderMoney3=new BigDecimal(0);
		BigDecimal orderMoney4=new BigDecimal(0);
		for(BookStockDO bookm:bookPurchaseDO){
			if(bookm.getBookType().indexOf("基础知识")!=-1){
				orderMoney1=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("初级")!=-1){
				orderMoney2=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("中级")!=-1){
				orderMoney3=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("高级")!=-1){
				orderMoney4=bookm.getMoney();
			}
		}
		//计算基础知识价格
		BigDecimal orderMoney=(money.multiply(orderMoney1)).multiply(bookOrder.getDiscount().divide(new BigDecimal(10)));

		//计算初级价格
		BigDecimal orderMoneys1=(money1.multiply(orderMoney2)).multiply(bookOrder.getDiscountPrimary().divide(new BigDecimal(10)));

		//计算中级价格
		BigDecimal orderMoneys2=(money2.multiply(orderMoney3)).multiply(bookOrder.getDiscountIntermediate().divide(new BigDecimal(10)));

		//计算高级价格
		BigDecimal orderMoneys3=(money3.multiply(orderMoney4)).multiply(bookOrder.getDiscountSenior().divide(new BigDecimal(10)));

		BigDecimal orderSumMoney=new BigDecimal(0);
		orderSumMoney=orderMoneys1.add(orderMoneys2).add(orderMoneys3).add(orderMoney);

		bookOrder.setOrderMoney(orderSumMoney);
		//基础知识折扣价
		bookOrder.setBasicsPayment(orderMoney);
		//初级折扣价
		bookOrder.setPrimaryDiscountPayment(orderMoneys1);
		//中级折扣价
		bookOrder.setIntermediatePayment(orderMoneys2);
		//中级折扣价
		bookOrder.setSeniorPayment(orderMoneys3);
		String department=null;
		EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();
		wrapper1.eq("userId",this.getUserId().toString());
		Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);
		for(UserRoleDO list:page1.getRecords()){

			EntityWrapper<RoleDO> wrapper2 = new EntityWrapper<>();
			wrapper2.eq("id",list.getRoleId());
			wrapper2.like("roleName","市场");
			//优先匹配市场人员权限
			List<RoleDO> roleDO=	roleService.selectList(wrapper2);
			if(roleDO.size()>0){
				department=roleDO.get(0).getRoleName();
				break;
			}

		}
		if(StringUtil.notEmpty(department)){
			bookOrder.setDepartment(department);
		}else {
			//这里匹配管理员权限
			for(UserRoleDO list:page1.getRecords()){
				EntityWrapper<RoleDO> wrapper2 = new EntityWrapper<>();
				wrapper2.eq("id",list.getRoleId());
				wrapper2.like("roleName","管理").or().like("roleName","超级");
				List<RoleDO> roleDO=	roleService.selectList(wrapper2);
				if(roleDO.size()>0){
					department=roleDO.get(0).getRoleName();
					break;
				}
			}
			bookOrder.setDepartment(department);
		}

		boolean b = bookOrderService.insert(bookOrder);
		Map<String,String> map = new HashMap<>();
		map.put("type","addordernotice");
		map.put("name","下单通知配置");
		String system_invoice = dictService.selDicBy(map);




		if(b) {
			//发送短信通知
			Object orgname=EhCacheUtil.get("下单通知"+system_invoice);
			//if(orgname==null){
				Wrapper<MessageplatfromDO> wrapperor = new EntityWrapper<MessageplatfromDO>();
				wrapperor.eq("name","下单通知");
				List<MessageplatfromDO> list=messageplatfromService.selectList(wrapperor);
				if(list.size()==0){
					return Result.fail("短信模板不存在！");
				}
				Map  map1org=new HashMap();
				SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//注意月份是MM
				map1org.put("time",simpleDateFormat.format(new Date()));
				smsSerevice.send(system_invoice,list.get(0).getSmsDemo(),map1org);
				EhCacheUtil.put("订单短信通知"+system_invoice,list.get(0).getSmsDemo());
			//}
		}
		return Result.ok();
	}

	/**
	 * 2020订单新增
	 * @param bookOrder
	 * @param district
	 * @return
	 */
	@Log("添加订单记录表")
	@ResponseBody
	@PostMapping("/save2020")
	@RequiresPermissions("jzweb:bookOrder:add")
	public Result<String> save2020( BookOrderDO bookOrder,String district){
		if(bookOrder.getBookId()==null){
			return Result.fail("请选择书籍种类！");
		}
		if(bookOrder.getOrderCreatetime()==null){
			return Result.fail("请选择订单创建时间！");
		}
		Wrapper<BookStockDO> wrapper = new EntityWrapper();
		wrapper.eq("book_types", bookOrder.getBookId());
		//查询价格
		List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper);

		if(bookPurchaseDO.size()==0){
			return Result.fail("订单价格出现异常，请联系管理员！");
		}
		if(!StringUtil.notEmpty(bookOrder.getSchool())){
			return Result.fail("学校名称不能为空或者系统中不存在！");
		}
		Page<Map<Object,Object>> listSchool=bookOrderService.selectSchool(1,10,bookOrder.getSchool());
		if(listSchool.getRecords().size()==0){
			return Result.fail("学校名称系统不存在！");
		}
		//
		String department=null;
		EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();
		wrapper1.eq("userId",this.getUserId().toString());
		Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);
		for(UserRoleDO list:page1.getRecords()){

			EntityWrapper<RoleDO> wrapper2 = new EntityWrapper<>();
			wrapper2.eq("id",list.getRoleId());
			wrapper2.like("roleName","市场");
			//优先匹配市场人员权限
			List<RoleDO> roleDO=	roleService.selectList(wrapper2);
			if(roleDO.size()>0){
				department=roleDO.get(0).getRoleName();
				break;
			}

		}
		if(StringUtil.notEmpty(department)){
			bookOrder.setDepartment(department);
		}else {
			//这里匹配管理员权限
			for(UserRoleDO list:page1.getRecords()){
				EntityWrapper<RoleDO> wrapper2 = new EntityWrapper<>();
				wrapper2.eq("id",list.getRoleId());
				wrapper2.like("roleName","管理").or().like("roleName","超级");
				List<RoleDO> roleDO=	roleService.selectList(wrapper2);
				if(roleDO.size()>0){
					department=roleDO.get(0).getRoleName();
					break;
				}
			}
			bookOrder.setDepartment(department);
		}
		bookOrder.setYear(2020);
		//bookOrder.setOrderCreatetime(new Date());
		bookOrder.setCreareUser(this.getUserId());
		bookOrder.setCounty(district);

		if(bookOrder.getDiscount().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}
		if(bookOrder.getDiscountIntermediate().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}
		if(bookOrder.getDiscountPrimary().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}
		if(bookOrder.getDiscountSenior().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}

		//折扣跟订单数量
		//计算基础知识折扣价格
		BigDecimal money=	BigDecimal.valueOf(bookOrder.getOrderNumber());
		//初级价格
		BigDecimal money1=	BigDecimal.valueOf(bookOrder.getOrderPrimary());
		//中级价格
		BigDecimal money2=	BigDecimal.valueOf(bookOrder.getOrderIntermediate());
		//高级价格
		BigDecimal money3=	BigDecimal.valueOf(bookOrder.getOrderSenior());

		BigDecimal orderMoney1=new BigDecimal(0);
		BigDecimal orderMoney2=new BigDecimal(0);
		BigDecimal orderMoney3=new BigDecimal(0);
		BigDecimal orderMoney4=new BigDecimal(0);
		for(BookStockDO bookm:bookPurchaseDO){
			if(bookm.getBookType().indexOf("基础知识")!=-1){
				orderMoney1=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("初级")!=-1){
				orderMoney2=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("中级")!=-1){
				orderMoney3=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("高级")!=-1){
				orderMoney4=bookm.getMoney();
			}
		}
		//计算基础知识价格
		BigDecimal orderMoney=(money.multiply(orderMoney1)).multiply(bookOrder.getDiscount().divide(new BigDecimal(10)));

		//计算初级价格
		BigDecimal orderMoneys1=(money1.multiply(orderMoney2)).multiply(bookOrder.getDiscountPrimary().divide(new BigDecimal(10)));

		//计算中级价格
		BigDecimal orderMoneys2=(money2.multiply(orderMoney3)).multiply(bookOrder.getDiscountIntermediate().divide(new BigDecimal(10)));

		//计算高级价格
		BigDecimal orderMoneys3=(money3.multiply(orderMoney4)).multiply(bookOrder.getDiscountSenior().divide(new BigDecimal(10)));

		BigDecimal orderSumMoney=new BigDecimal(0);
		orderSumMoney=orderMoneys1.add(orderMoneys2).add(orderMoneys3).add(orderMoney);

		bookOrder.setOrderMoney(orderSumMoney);
		bookOrder.setOrderType(0);
		//基础知识折扣价
		bookOrder.setBasicsPayment(orderMoney);
		//初级折扣价
		bookOrder.setPrimaryDiscountPayment(orderMoneys1);
		//中级折扣价
		bookOrder.setIntermediatePayment(orderMoneys2);
		//中级折扣价
		bookOrder.setSeniorPayment(orderMoneys3);
		boolean b = bookOrderService.insert(bookOrder);
		Map<String,String> map = new HashMap<>();
		map.put("type","addordernotice");
		map.put("name","下单通知配置");
		String system_invoice = dictService.selDicBy(map);

		if(b) {
			//发送短信通知
			Object orgname=EhCacheUtil.get("下单通知"+system_invoice);
			//	if(orgname==null){
			Wrapper<MessageplatfromDO> wrapperor = new EntityWrapper<MessageplatfromDO>();
			wrapperor.eq("name","下单通知");
			List<MessageplatfromDO> list=messageplatfromService.selectList(wrapperor);
			if(list.size()==0){
				return Result.fail("短信模板不存在！");
			}
			Map  map1org=new HashMap();
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//注意月份是MM
			map1org.put("time",simpleDateFormat.format(new Date()));
			smsSerevice.send(system_invoice,list.get(0).getSmsDemo(),map1org);
			EhCacheUtil.put("订单短信通知"+system_invoice,list.get(0).getSmsDemo());
			//	}
		}
		return Result.ok();
	}

	/**
	 * 这里计算订单价格
	 * @param bookOrder
	 * @param district
	 * @return
	 */
	@Log("添加订单记录表")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:bookOrder:add")
	public Result<String> save( BookOrderDO bookOrder,String district){
		if(bookOrder.getBookId()==null){
			return Result.fail("请选择书籍种类！");
		}
		if(bookOrder.getOrderCreatetime()==null){
			return Result.fail("请选择订单创建时间！");
		}
		Wrapper<BookStockDO> wrapper = new EntityWrapper();
		wrapper.eq("book_types", bookOrder.getBookId());
		//查询价格
		List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper);

		if(bookPurchaseDO.size()==0){
			return Result.fail("订单价格出现异常，请联系管理员！");
		}

		if(!StringUtil.notEmpty(bookOrder.getSchool())){
			return Result.fail("学校名称不能为空或者系统中不存在！");
		}
		Page<Map<Object,Object>> listSchool=bookOrderService.selectSchool(1,10,bookOrder.getSchool());
		if(listSchool.getRecords().size()==0){
			return Result.fail("学校名称系统不存在！");
		}
		String department=null;
		EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();
		wrapper1.eq("userId",this.getUserId().toString());
		Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);
		for(UserRoleDO list:page1.getRecords()){

			EntityWrapper<RoleDO> wrapper2 = new EntityWrapper<>();
			wrapper2.eq("id",list.getRoleId());
			wrapper2.like("roleName","市场");
			//优先匹配市场人员权限
			List<RoleDO> roleDO=	roleService.selectList(wrapper2);
			if(roleDO.size()>0){
				department=roleDO.get(0).getRoleName();
				break;
			}

		}
		if(StringUtil.notEmpty(department)){
			bookOrder.setDepartment(department);
		}else {
			//这里匹配管理员权限
			for(UserRoleDO list:page1.getRecords()){
				EntityWrapper<RoleDO> wrapper2 = new EntityWrapper<>();
				wrapper2.eq("id",list.getRoleId());
				wrapper2.like("roleName","管理").or().like("roleName","超级");
				List<RoleDO> roleDO=	roleService.selectList(wrapper2);
				if(roleDO.size()>0){
					department=roleDO.get(0).getRoleName();
					break;
				}
			}
			bookOrder.setDepartment(department);
		}

		//bookOrder.setOrderCreatetime(new Date());
		bookOrder.setCreareUser(this.getUserId());
		bookOrder.setCounty(district);

		if(bookOrder.getDiscount().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}
		if(bookOrder.getDiscountIntermediate().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}
		if(bookOrder.getDiscountPrimary().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}
		if(bookOrder.getDiscountSenior().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}

		//折扣跟订单数量
		//计算基础知识折扣价格
		BigDecimal money=	BigDecimal.valueOf(bookOrder.getOrderNumber());
		//初级价格
		BigDecimal money1=	BigDecimal.valueOf(bookOrder.getOrderPrimary());
		//中级价格
		BigDecimal money2=	BigDecimal.valueOf(bookOrder.getOrderIntermediate());
		//高级价格
		BigDecimal money3=	BigDecimal.valueOf(bookOrder.getOrderSenior());

		BigDecimal orderMoney1=new BigDecimal(0);
		BigDecimal orderMoney2=new BigDecimal(0);
		BigDecimal orderMoney3=new BigDecimal(0);
		BigDecimal orderMoney4=new BigDecimal(0);
		for(BookStockDO bookm:bookPurchaseDO){
			if(bookm.getBookType().indexOf("基础知识")!=-1){
				orderMoney1=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("初级")!=-1){
				orderMoney2=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("中级")!=-1){
				orderMoney3=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("高级")!=-1){
				orderMoney4=bookm.getMoney();
			}
		}
		//计算基础知识价格
		BigDecimal orderMoney=(money.multiply(orderMoney1)).multiply(bookOrder.getDiscount().divide(new BigDecimal(10)));

		//计算初级价格
		BigDecimal orderMoneys1=(money1.multiply(orderMoney2)).multiply(bookOrder.getDiscountPrimary().divide(new BigDecimal(10)));

		//计算中级价格
		BigDecimal orderMoneys2=(money2.multiply(orderMoney3)).multiply(bookOrder.getDiscountIntermediate().divide(new BigDecimal(10)));

		//计算高级价格
		BigDecimal orderMoneys3=(money3.multiply(orderMoney4)).multiply(bookOrder.getDiscountSenior().divide(new BigDecimal(10)));

		BigDecimal orderSumMoney=new BigDecimal(0);
		orderSumMoney=orderMoneys1.add(orderMoneys2).add(orderMoneys3).add(orderMoney);

		bookOrder.setOrderMoney(orderSumMoney);
		bookOrder.setOrderType(0);
		//基础知识折扣价
		bookOrder.setBasicsPayment(orderMoney);
		//初级折扣价
		bookOrder.setPrimaryDiscountPayment(orderMoneys1);
		//中级折扣价
		bookOrder.setIntermediatePayment(orderMoneys2);
		//中级折扣价
		bookOrder.setSeniorPayment(orderMoneys3);
		boolean b = bookOrderService.insert(bookOrder);
		Map<String,String> map = new HashMap<>();
		map.put("type","addordernotice");
		map.put("name","下单通知配置");
		String system_invoice = dictService.selDicBy(map);

		if(b) {
			//发送短信通知
			Object orgname=EhCacheUtil.get("下单通知"+system_invoice);
		//	if(orgname==null){
				Wrapper<MessageplatfromDO> wrapperor = new EntityWrapper<MessageplatfromDO>();
				wrapperor.eq("name","下单通知");
				List<MessageplatfromDO> list=messageplatfromService.selectList(wrapperor);
				if(list.size()==0){
					return Result.fail("短信模板不存在！");
				}
				Map  map1org=new HashMap();
				SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//注意月份是MM
				map1org.put("time",simpleDateFormat.format(new Date()));
				smsSerevice.send(system_invoice,list.get(0).getSmsDemo(),map1org);
				EhCacheUtil.put("订单短信通知"+system_invoice,list.get(0).getSmsDemo());
		//	}
		}
        return Result.ok();
	}
	
	@Log("修改订单记录表")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:bookOrder:edit")
	public Result<String>  update( BookOrderDO bookOrder,String district){
		if(StringUtil.isNotNull(district)){
			bookOrder.setCounty(district);
		}
		Wrapper<BookStockDO> wrapper = new EntityWrapper();
		wrapper.eq("book_types", bookOrder.getBookId());
		//查询价格
		List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper);

		// 查询列表数据
		int is=0;
		Long roleId=0l;
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//查询所有用户所属权限
		List<String> organizationNewsDOS = userRoleService.selroleNameList(this.getUserId());

		//for(RoleDO li:listRole){
		for(String name:organizationNewsDOS){

			if(name.equals("订单审核专员")){
				is=2;
			}else if(name.equals("订单发布专员")){
				is=1;
			}else if(name.equals("金职仓库审核专员")){
				is=3;
			}else if(name.equals("超级用户角色")){
				is=4;
				break;
			}else if(name.equals("金英仓库审核专员")){
				is=5;
			}else if(name.equals("市场一部管理员")){
				is=6;
			}else if(name.equals("市场二部管理员")){
				is=7;
			}else if(name.equals("市场一部")){
				is=8;
			}else if(name.equals("市场二部")){
				is=9;
			}else if(name.equals("财务审核发票")){
				is=10;
			}else if(name.equals("管理员")){
				is=11;
				break;
			}
		}
		if(is==8||is==9||is==10){
			return Result.fail("无权限修改订单！");
		}

		if(bookPurchaseDO.size()==0){
			return Result.fail("订单价格出现异常，请联系管理员！");
		}
		if(bookOrder.getDiscount().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}
		if(bookOrder.getDiscountIntermediate().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}
		if(bookOrder.getDiscountPrimary().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}
		if(bookOrder.getDiscountSenior().compareTo(new BigDecimal(10))>0){
			return Result.fail("折扣不能大于10");
		}
		//折扣跟订单数量
		//计算基础知识折扣价格
		BigDecimal money=	BigDecimal.valueOf(bookOrder.getOrderNumber());
		//初级价格
		BigDecimal money1=	BigDecimal.valueOf(bookOrder.getOrderPrimary());
		//中级价格
		BigDecimal money2=	BigDecimal.valueOf(bookOrder.getOrderIntermediate());
		//高级价格
		BigDecimal money3=	BigDecimal.valueOf(bookOrder.getOrderSenior());
		BigDecimal orderMoney1=new BigDecimal(0);
		BigDecimal orderMoney2=new BigDecimal(0);
		BigDecimal orderMoney3=new BigDecimal(0);
		BigDecimal orderMoney4=new BigDecimal(0);
		for(BookStockDO bookm:bookPurchaseDO){
			if(bookm.getBookType().indexOf("基础知识")!=-1){
				orderMoney1=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("初级")!=-1){
				orderMoney2=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("中级")!=-1){
				orderMoney3=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("高级")!=-1){
				orderMoney4=bookm.getMoney();
			}
		}
		//计算基础知识价格
		BigDecimal orderMoney=(money.multiply(orderMoney1)).multiply(bookOrder.getDiscount().divide(new BigDecimal(10)));

		//计算初级价格
		BigDecimal orderMoneys1=(money1.multiply(orderMoney2)).multiply(bookOrder.getDiscountPrimary().divide(new BigDecimal(10)));

		//计算中级价格
		BigDecimal orderMoneys2=(money2.multiply(orderMoney3)).multiply(bookOrder.getDiscountIntermediate().divide(new BigDecimal(10)));

		//计算高级价格
		BigDecimal orderMoneys3=(money3.multiply(orderMoney4)).multiply(bookOrder.getDiscountSenior().divide(new BigDecimal(10)));

		BigDecimal orderSumMoney=new BigDecimal(0);
		orderSumMoney=orderMoneys1.add(orderMoneys2).add(orderMoneys3).add(orderMoney);

		bookOrder.setOrderMoney(orderSumMoney);
		//基础知识折扣价
		bookOrder.setBasicsPayment(orderMoney);
		//初级折扣价
		bookOrder.setPrimaryDiscountPayment(orderMoneys1);
		//中级折扣价
		bookOrder.setIntermediatePayment(orderMoneys2);
		//中级折扣价
		bookOrder.setSeniorPayment(orderMoneys3);

		if(!StringUtil.notEmpty(bookOrder.getSchool())){
			BookOrderDO bookOrderDO1=	bookOrderService.selectById(bookOrder.getId());
			bookOrder.setSchool(bookOrderDO1.getSchool());

		}


		boolean update = bookOrderService.updateById(bookOrder);
		return update ? Result.ok() : Result.fail();
	}

	@Log("修改订单记录表")
	@ResponseBody
	@RequestMapping("/update1")
	@RequiresPermissions("jzweb:bookOrder:edit")
	public Result<String>  update1( BookOrderDO bookOrder,String district){
		if(StringUtil.isNotNull(district)){
			bookOrder.setCounty(district);
		}
		Wrapper<BookStockDO> wrapper = new EntityWrapper();
		wrapper.eq("book_types", bookOrder.getBookId());
		//查询价格
		List<BookStockDO> bookPurchaseDO=bookStockService.selectList(wrapper);

		int is=0;
		Long roleId=0l;
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//查询所有用户所属权限
		List<String> organizationNewsDOS = userRoleService.selroleNameList(this.getUserId());

		//for(RoleDO li:listRole){
		for(String name:organizationNewsDOS){

			if(name.equals("订单审核专员")){
				is=2;
			}else if(name.equals("订单发布专员")){
				is=1;
			}else if(name.equals("金职仓库审核专员")){
				is=3;
			}else if(name.equals("超级用户角色")){
				is=4;
				break;
			}else if(name.equals("金英仓库审核专员")){
				is=5;
			}else if(name.equals("市场一部管理员")){
				is=6;
			}else if(name.equals("市场二部管理员")){
				is=7;
			}else if(name.equals("市场一部")){
				is=8;
			}else if(name.equals("市场二部")){
				is=9;
			}else if(name.equals("财务审核发票")){
				is=10;
			}else if(name.equals("管理员")){
				is=11;
				break;
			}
		}
		if(is==8||is==9||is==10){
			return Result.fail("无权限修改订单！");
		}

		if(bookPurchaseDO.size()==0){
			return Result.fail("订单价格出现异常，请联系管理员！");
		}
		bookOrder.setDiscount(new BigDecimal(10));
		bookOrder.setDiscountIntermediate(new BigDecimal(10));
		bookOrder.setDiscountPrimary(new BigDecimal(10));
		bookOrder.setDiscountSenior(new BigDecimal(10));
		//折扣跟订单数量
		//计算基础知识折扣价格
		BigDecimal money=	BigDecimal.valueOf(bookOrder.getOrderNumber());
		//初级价格
		BigDecimal money1=	BigDecimal.valueOf(bookOrder.getOrderPrimary());
		//中级价格
		BigDecimal money2=	BigDecimal.valueOf(bookOrder.getOrderIntermediate());
		//高级价格
		BigDecimal money3=	BigDecimal.valueOf(bookOrder.getOrderSenior());
		BigDecimal orderMoney1=new BigDecimal(0);
		BigDecimal orderMoney2=new BigDecimal(0);
		BigDecimal orderMoney3=new BigDecimal(0);
		BigDecimal orderMoney4=new BigDecimal(0);
		for(BookStockDO bookm:bookPurchaseDO){
			if(bookm.getBookType().indexOf("基础知识")!=-1){
				orderMoney1=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("初级")!=-1){
				orderMoney2=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("中级")!=-1){
				orderMoney3=bookm.getMoney();
			}else if(bookm.getBookType().indexOf("高级")!=-1){
				orderMoney4=bookm.getMoney();
			}
		}
		//计算基础知识价格
		BigDecimal orderMoney=(money.multiply(orderMoney1)).multiply(bookOrder.getDiscount().divide(new BigDecimal(10)));

		//计算初级价格
		BigDecimal orderMoneys1=(money1.multiply(orderMoney2)).multiply(bookOrder.getDiscountPrimary().divide(new BigDecimal(10)));

		//计算中级价格
		BigDecimal orderMoneys2=(money2.multiply(orderMoney3)).multiply(bookOrder.getDiscountIntermediate().divide(new BigDecimal(10)));

		//计算高级价格
		BigDecimal orderMoneys3=(money3.multiply(orderMoney4)).multiply(bookOrder.getDiscountSenior().divide(new BigDecimal(10)));

		BigDecimal orderSumMoney=new BigDecimal(0);
		orderSumMoney=orderMoneys1.add(orderMoneys2).add(orderMoneys3).add(orderMoney);

		bookOrder.setOrderMoney(orderSumMoney);
		//基础知识折扣价
		bookOrder.setBasicsPayment(orderMoney);
		//初级折扣价
		bookOrder.setPrimaryDiscountPayment(orderMoneys1);
		//中级折扣价
		bookOrder.setIntermediatePayment(orderMoneys2);
		//中级折扣价
		bookOrder.setSeniorPayment(orderMoneys3);

		boolean update = bookOrderService.updateById(bookOrder);
		return update ? Result.ok() : Result.fail();
	}


	@Log("修改订单记录表")
	@ResponseBody
	@RequestMapping("/updateCw")
	@RequiresPermissions("jzweb:bookOrder:editCw")
	public Result<String>  updateCw( BookOrderDO bookOrder){

		boolean update = bookOrderService.updateById(bookOrder);
		return update ? Result.ok() : Result.fail();
	}

	/**
	 * 主管审核
	 * @param bookOrder
	 * @return
	 */
	@Log("主管审核订单")
	@ResponseBody
	@RequestMapping("/updateZG")
	@RequiresPermissions("jzweb:bookOrder:editZG")
	public Result<String>  updateZG( BookOrderDO bookOrder){
			if(bookOrder.getState()==1){
				Map<String,String> map = new HashMap<>();
				map.put("type","addordernotice");
				map.put("name","下单通知配置");
				String system_invoice = dictService.selDicBy(map);

				Wrapper<MessageplatfromDO> wrapperor = new EntityWrapper<MessageplatfromDO>();
				wrapperor.eq("name","免费订单下单");
				List<MessageplatfromDO> list=messageplatfromService.selectList(wrapperor);
				if(list.size()==0){
					return Result.fail("短信模板不存在！");
				}
				Map  map1org=new HashMap();
				SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//注意月份是MM
				map1org.put("time",simpleDateFormat.format(new Date()));
				smsSerevice.send(system_invoice,list.get(0).getSmsDemo(),map1org);
				EhCacheUtil.put("订单短信通知"+system_invoice,list.get(0).getSmsDemo());
			}
		boolean update = bookOrderService.updateById(bookOrder);
		return update ? Result.ok() : Result.fail();
	}

	/**
	 * 订单审核提交
	 * 这里需要判断仓库是否有库存
	 * @param bookOrder
	 * @return
	 */
	@Log("修改订单记录表")
	@ResponseBody
	@RequestMapping("/dDupdate")
	@RequiresPermissions("jzweb:bookOrder:dDupdate")
	public Result<String>  dDupdate( BookOrderDO bookOrder){

		BookOrderDO bookOrders = bookOrderService.selectById(bookOrder.getId());
		if(bookOrders.getState()>2){
			return	Result.fail("仓库管理员已经审核，订单不能重新审核！");
		}

		//订单审核人员
		bookOrder.setOrderUser(this.getUserId());

		//查询所选择的批次库存
		Map map= bookPurchaseService.numBook(bookOrders.getBookId().toString());


		if(map==null){
			return	Result.fail("所属仓库不存在");
		}

		if(bookOrder.getState()==1){


			//查询初级总库存
			Map bookStockC=new HashMap();
			bookStockC.put("bookTypes",bookOrders.getBookId());
			bookStockC.put("bookType","初级");
			Integer listcj=bookStockService.listStock(bookStockC);


			//查询初级总库存
			Map bookStockZ=new HashMap();
			bookStockZ.put("bookTypes",bookOrders.getBookId());
			bookStockZ.put("bookType","中级");
			Integer listzj=bookStockService.listStock(bookStockZ);

			//查询高级总库存
			Map bookStockG=new HashMap();
			bookStockG.put("bookTypes",bookOrders.getBookId());
			bookStockG.put("bookType","高级");
			Integer listgj=bookStockService.listStock(bookStockG);

			//查询高级总库存
			Map bookStockll=new HashMap();
			bookStockll.put("bookTypes",bookOrders.getBookId());
			bookStockll.put("bookType","基础知识");
			Integer listgll=bookStockService.listStock(bookStockll);

			//查询书籍数量
			Map map1=new HashMap();
			map1.put("name",bookOrders.getBookId());
			//查询总销量
			Map maostock=bookStockService.integerSales(map1);

			Integer integerSales1=Integer.valueOf(maostock.get("num1").toString());
			Integer integerSales2=Integer.valueOf(maostock.get("num2").toString());
			Integer integerSales3=Integer.valueOf(maostock.get("num3").toString());
			Integer integerSales4=Integer.valueOf(maostock.get("num4").toString());

			//基础知识
			 Integer inti1=listgll-integerSales1-bookOrders.getOrderNumber();
			 //初级
			Integer inti2=listcj-integerSales2-bookOrders.getOrderPrimary();
			//中级
			Integer inti3=listzj-integerSales3-bookOrders.getOrderIntermediate();
			//高级
			Integer inti4=listgj-integerSales4-bookOrders.getOrderSenior();

			if(inti1<0){
				return	Result.fail("基础知识库存不足！");
			}
			if(inti2<0){
				return	Result.fail("初级库存不足！");
			}
			if(inti3<0){
				return	Result.fail("中级库存不足！");
			}

			if(inti4<0){
				return	Result.fail("高级库存不足！");
			}
		}

		boolean update = bookOrderService.updateById(bookOrder);
		return update ? Result.ok() : Result.fail();
	}
	/**
	 * 仓库管理审核提交
	 * 这里只需要判断审核状态就可以了
	 *
	 * @param bookOrder
	 * @return
	 */
	@Log("修改订单记录表")
	@ResponseBody
	@RequestMapping("/cKupdate")
	@RequiresPermissions("jzweb:bookOrder:cKupdate")
	public Result<String>  cKupdate( BookOrderDO bookOrder) {
		BookOrderDO bookOrders = bookOrderService.selectById(bookOrder.getId());

		//订单审核人员
		bookOrder.setOrderUser(this.getUserId());

		//查询所选择的批次库存
		Map map = bookPurchaseService.numBook(bookOrders.getBookId().toString());


		if (map == null) {
			return Result.fail("所属仓库不存在");
		}

		Wrapper<DictDO> wrapper1s = new EntityWrapper();
		wrapper1s.eq("type","ckupdate");
		//查询价格
		List<DictDO> bookPurchaseDO=dictService.selectList(wrapper1s);

		boolean isck=false;
		//1 是开启此判断    0是关闭
		if(bookPurchaseDO.get(0).getValue().equals("1")){
			isck=true;
		}


		if (isck) {
			//查询初级总库存
			Map bookStockC = new HashMap();
			bookStockC.put("bookTypes", bookOrders.getBookId());
			bookStockC.put("bookType", "初级");
			Integer listcj = bookStockService.listStock(bookStockC);


			//查询初级总库存
			Map bookStockZ = new HashMap();
			bookStockZ.put("bookTypes", bookOrders.getBookId());
			bookStockZ.put("bookType", "中级");
			Integer listzj = bookStockService.listStock(bookStockZ);

			//查询高级总库存
			Map bookStockG = new HashMap();
			bookStockG.put("bookTypes", bookOrders.getBookId());
			bookStockG.put("bookType", "高级");
			Integer listgj = bookStockService.listStock(bookStockG);

			//查询高级总库存
			Map bookStockll = new HashMap();
			bookStockll.put("bookTypes", bookOrders.getBookId());
			bookStockll.put("bookType", "基础知识");
			Integer listgll = bookStockService.listStock(bookStockll);

			//查询书籍数量
			Map map1 = new HashMap();
			map1.put("name", bookOrders.getBookId());
			//查询总销量
			Map maostock = bookStockService.integerSales(map1);

			Integer integerSales1 = Integer.valueOf(maostock.get("num1").toString());
			Integer integerSales2 = Integer.valueOf(maostock.get("num2").toString());
			Integer integerSales3 = Integer.valueOf(maostock.get("num3").toString());
			Integer integerSales4 = Integer.valueOf(maostock.get("num4").toString());

			//基础知识
			Integer inti1 = listgll - integerSales1 - bookOrders.getOrderNumber();
			//初级
			Integer inti2 = listcj - integerSales2 - bookOrders.getOrderPrimary();
			//中级
			Integer inti3 = listzj - integerSales3 - bookOrders.getOrderIntermediate();
			//高级
			Integer inti4 = listgj - integerSales4 - bookOrders.getOrderSenior();

			if (inti1 < 0) {
				return Result.fail("基础知识库存不足！");
			}
			if (inti2 < 0) {
				return Result.fail("初级库存不足！");
			}
			if (inti3 < 0) {
				return Result.fail("中级库存不足！");
			}

			if (inti4 < 0) {
				return Result.fail("高级库存不足！");
			}
//			if (bookOrders.getState() == 0) {
//				return Result.fail("订单财务未审核，不能进行审核！");
//			}
//
//			if (bookOrders.getStateCollection() == 0) {
//				return Result.fail("收款状态未审核，不能进行审核！");
//			}

		}
			//仓库管理审核人员
			bookOrder.setGoodsUser(this.getUserId());

			boolean update = bookOrderService.updateById(bookOrder);
			if(update){
				//发送短信通知
				Object orgname=EhCacheUtil.get("订单短信通知"+bookOrder.getMobile());
				if(orgname==null){
					Wrapper<MessageplatfromDO> wrapper = new EntityWrapper<MessageplatfromDO>();
					wrapper.eq("name","订单短信通知");
					List<MessageplatfromDO> list=messageplatfromService.selectList(wrapper);
					if(list.size()==0){
						return Result.fail("短信模板不存在！");
					}
					Map  map1org=new HashMap();
					map1org.put("name",bookOrder.getExpressName());
					map1org.put("code",bookOrder.getOrderCode());
					smsSerevice.send(bookOrder.getMobile(),list.get(0).getSmsDemo(),map1org);
					EhCacheUtil.put("订单短信通知"+bookOrder.getMobile(),list.get(0).getSmsDemo());
				}

			}
			return update ? Result.ok() : Result.fail();

	}

	@Log("删除订单记录表")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:bookOrder:remove")
	public Result<String>  remove( Long id){
		bookOrderService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除订单记录表")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:bookOrder:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		bookOrderService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}


	@GetMapping("/examineCk/{id}")
	@RequiresPermissions("jzweb:bookOrder:examineCk")
	String examineCk(@PathVariable("id") Long id,Model model){
		BookOrderDO bookOrder = bookOrderService.selectById(id);
		model.addAttribute("bookOrder", bookOrder);
		return "jzweb/bookOrder/examineCk";
	}
}
